Jump to content

Recommended Posts

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).

 

Link to comment
https://forums.phpfreaks.com/topic/71330-multi-curl-mcurl-and-timeout-in-php5/
Share on other sites

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.

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.