Jump to content

multi curl - mCURL and Timeout in PHP5


sbutt

Recommended Posts

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.

   

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.