sbutt Posted September 25, 2007 Share Posted September 25, 2007 Hello Guys, I have heard that in php5 there is a built in support for mCURL or in other words it is possible to open multiple parallel connections with different feeds/urls? Now if the above is true then somebody please also tell me if it is possible to set a timeout (in millisecond) for each single connection as opposed to set a global timeout connection for all the feeds? In Nutt-shell, I want to find out, how this mCURL feature (if possible) handles timeouts on a single feed level? Any small code snippet help would be really appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/ Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 Hmmm, possibly use curl_setopt() with the CURLOPT_TIMEOUT option. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354865 Share on other sites More sharing options...
sbutt Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks for your reply, but could you please write me a small code snipped with more than 1 parallel connections and timeout(in millisecond) for each connection set seperatly, using mcurl? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354874 Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 It can't be set in milliseconds, only seconds. As for a code snippet, have you read the manual? There's a good example there. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354881 Share on other sites More sharing options...
sbutt Posted September 25, 2007 Author Share Posted September 25, 2007 Thank you indeed for your help! Have you by any chance heard of 'curl_easy_setopt()', becuase it has this parameter 'CURLOPT_TIMEOUT_MS' that can be used to provide timeout in millisecond. But when i do that i get the error : Fatal error: Call to undefined function curl_easy_setopt() .. my current curl version is: curl=/opt/curl-7-15-3. I tried to find out curl release verion that contains curl_easy_setopt() but no success Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354932 Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 That version is too old, you'd need version 7.16.2 (I got this info from the cURL website) Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354946 Share on other sites More sharing options...
sbutt Posted September 25, 2007 Author Share Posted September 25, 2007 that's correct that 7.17.0, is the most recent version but it would be nice (just out of curiosity!) to know in which curl version 'cury_easy_setopt()' was introduced or in other words with which i can use: curl_easy_setopt($ch1, CURLOPT_TIMEOUT_MS, 0);' Again it's just out of curiosity! Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354952 Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 that's correct that 7.17.0, is the most recent version but it would be nice (just out of curiosity!) to know in which curl version 'cury_easy_setopt()' was introduced That's what I gave you... 7.16.2 I never mentioned the latest version. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354964 Share on other sites More sharing options...
sbutt Posted September 25, 2007 Author Share Posted September 25, 2007 Ohh sorry thanks! Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-354970 Share on other sites More sharing options...
sbutt Posted September 28, 2007 Author Share Posted September 28, 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). thanks. Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-357155 Share on other sites More sharing options...
HuggieBear Posted October 1, 2007 Share Posted October 1, 2007 There's no PHP function called curl_easy_setopt(). That's what the problem is. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70620-multi-curl-mcurl-and-timeout-in-php5/#findComment-359023 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.