ob_start (); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://$url?a=$a&b=$b"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); $data = ob_get_contents (); ob_end_clean (); ------------ it seems take long time to run this scripts. or can't release memory or close it. someone can help me?, i need right properly curl code thank you
<?php $ch = curl_init(); $options = array( CURLOPT_URL => "http://{$url}?a={$a}&b={$b}", CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, ); curl_setopt_array($options); $data = curl_exec($ch); curl_close($ch); PHP:
thanks so much. beside, if it's a pure url. example:http://mydomain.com/abc/123.php is below code that are right? $ch = curl_init(); CURLOPT_URL => "http://mydomain.com/abc/123.php", CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, curl_setopt_array($options); $data = curl_exec($ch); curl_close($ch); echo "$data"; PHP: thanks
Unfortunately not. You've left out the array function <?php // Start the CURL handle. $ch = curl_init(); // Define the options for CURL in an array. $options = array( // Set the URL to fetch. CURLOPT_URL => "http://mydomain.com/abc/123.php", // Don't return the headers. CURLOPT_HEADER => 0, // Set the page fetch timeout to 5 seconds. CURLOPT_CONNECTTIMEOUT => 5, // Return the data (usually html or xml) CURLOPT_RETURNTRANSFER => TRUE, // Don't verify the certificate (helps with retrieving non ssl sites. CURLOPT_SSL_VERIFYPEER => FALSE, // Don't verify the certificate host CURLOPT_SSL_VERIFYHOST => FALSE, ); // Set the CURL options from the array. curl_setopt_array($options); // Execute the request and store it in a variable. $data = curl_exec($ch); // Close the CURL handle. curl_close($ch); // Echo the CURL's returned data. echo "$data"; PHP: Here is the uncommented version: $ch = curl_init(); $options = array( CURLOPT_URL => "http://mydomain.com/abc/123.php", CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, ); curl_setopt_array($options); $data = curl_exec($ch); curl_close($ch); echo "$data"; PHP: