cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

curl_easy_init + curl_easy_setopt + timeout in milliseconds 'CURLOPT_TIMEOUT_MS'

From: Suleman Butt <suleman.butt_at_gmail.com>
Date: Fri, 28 Sep 2007 19:26:17 +0200

Hi Folks,
          I'm using PHP 5.2.4 with curl-7.17.0 patch. Now when I run this
following small code snippet,

Code:
<?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_MS, 500);
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.
I have also tried $ch1 = curl_easy_init();
but then i get the error: Fatal error: Call to undefined function
curl_easy_init() ..at line 3.

Now could anybody please tell me how can i use 'curl_easy_setopt()' function
with "CURLOPT_TIMEOUT_MS" 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).

To my knowledge, setting Execution Timout in milliseconds (
CURLOPT_TIMEOUT_MS) is only possible thrrough easy functions (curl_easy_init,
curl_easy_setopt), but i can't figure it out how to handle this fatal errro
:(..pls help anybody.

thanks.

-- 
Regards Suleman

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-09-28