sbutt Posted October 1, 2007 Share Posted October 1, 2007 Hi Folks, I'm using PHP 5.2.4 with curl-7.17.0 patch. Now when I run this following small code snippet, <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_easy_setopt($ch1, CURLOPT_URL, "http://www.example.com/"); curl_easy_setopt($ch1, CURLOPT_TIMEOUT, 5); curl_easy_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch2, CURLOPT_TIMEOUT, 5); curl_setopt($ch2, CURLOPT_HEADER, 0); //create the multiple cURL handle $mh = curl_multi_init(); //add the two handles curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $running=null; //execute the handles do { curl_multi_exec($mh,$running); if($running == 0){ echo "Suleman"; echo "||"; echo $running; } } while ($running > 0); //close the handles curl_multi_remove_handle($mh,$ch1); curl_multi_remove_handle($mh,$ch2); curl_multi_close($mh); ?> I get this error: Fatal error: Call to undefined function curl_easy_setopt() ..at line 7. Now could anybody please tell me how can i use 'curl_easy_setopt()' function with "CURLOPT_TIMEOUT" option? The default curl_setopt() method with simple timeout param provides timeout value only in seconds, where as i want to set the value for the timeout in milliseconds. And i'm opening parallel connections to the urls (multi curl). Quote Link to comment https://forums.phpfreaks.com/topic/71330-multi-curl-mcurl-and-timeout-in-php5/ Share on other sites More sharing options...
Orio Posted October 1, 2007 Share Posted October 1, 2007 There's no such function as curl_easy_setopt()... If you want to use milliseconds instead of seconds, try: <?php curl_setopt($ch1, CURL_TIMEOUT, 5/1000); ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/71330-multi-curl-mcurl-and-timeout-in-php5/#findComment-358918 Share on other sites More sharing options...
sbutt Posted October 1, 2007 Author Share Posted October 1, 2007 curl_setopt($ch1, CURLOPT_TIMEOUT, 500/1000); ==> 0.5 seconds This change makes the application hang. If i increase the value to curl_setopt($ch1, CURLOPT_TIMEOUT, 1500/1000); ==> 1.5 seconds This works but then i guess it takes the rounded integeral value that is 1 in this case and leave the rest. In case of 0.5 seconds as there is no integeral value so it hangs. Just my guess. Quote Link to comment https://forums.phpfreaks.com/topic/71330-multi-curl-mcurl-and-timeout-in-php5/#findComment-359059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.