#43077 [Opn->Fbk]: curl_multi_exec does not report errors
| From: | jani@php.net | Date: | Thu, 25 Oct 2007 13:21:31 +0000 |
| Subject: | #43077 [Opn->Fbk]: curl_multi_exec does not report errors | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118943@lists.php.net to get a copy of this message | ||
ID: 43077
Updated by: jani@php.net
Reported By: robert dot reichel at boboton dot com
-Status: Open
+Status: Feedback
Bug Type: cURL related
Operating System: Windows XP
PHP Version: 5.2.4
New Comment:
You should be using curl_multi_info_read() instead:
http://php.net/curl_multi_info_read
Previous Comments:
------------------------------------------------------------------------
[2007-10-23 08:08:53] robert dot reichel at boboton dot com
Description:
------------
curl_error does not produce error message when used with
curl_multi_exec. The results are not same each time you execute provided
code.
Reproduce code:
---------------
<?php
function fetchData($URLs)
{
// set empty lists
$errors = array();
$cache = array();
//create the multiple cURL handle
$mh = curl_multi_init();
foreach($URLs as $i=>$URL)
{
// initialize a cURL session
$sessions[$i] = curl_init();
// set URL and other appropriate options
curl_setopt($sessions[$i], CURLOPT_URL, $URL);
curl_setopt($sessions[$i], CURLOPT_HEADER, 0);
curl_setopt($sessions[$i], CURLOPT_RETURNTRANSFER, 1);
//add handles
curl_multi_add_handle($mh, $sessions[$i]);
}
//execute the handles
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
foreach($sessions as $i=>$session)
{
// get file content
if (curl_multi_getcontent($session) == false) {
$errors[$i] = curl_error($session);
}
// remove handle
curl_multi_remove_handle($mh, $sessions[$i]);
}
// close multi handle
curl_multi_close($mh);
return $errors;
}
/*--- CASE 'A' ---*/
// valid URLs
$URLsA[] = 'http://www.google.com/';
$URLsA[] = 'http://www.yahoo.com/';
// Invalid URL. This site does not exist. This should produce an error
message.
$URLsA[] = 'http://www.mysite-abc123.com/';
$errorsA = fetchData($URLsA);
print_r($errorsA);
/*--- CASE 'B' ---*/
// valid URL
$URLsB[] = 'http://www.google.com/';
// Invalid URL. This site does not exist. This should produce an error
message,
$URLsB[] = 'http://www.mysite-abc123.com/';
// valid URL
$URLsB[] = 'http://www.yahoo.com/';
$errorsB = fetchData($URLsB);
print_r($errorsB);
?>
Expected result:
----------------
Array
{
[2] => Couldn't resolve host 'www.mysite-abc123.com'
}
Array
{
[1] => Couldn't resolve host 'www.mysite-abc123.com'
}
Actual result:
--------------
The result is not always same. In most cases it's like this:
Array
{
[2] =>
Array
{
[1] =>
}
In rare cases it's like this:
Array
{
[2] =>
}
Array
{
[1] => Couldn't resolve host 'www.mysite-abc123.com'
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43077&edit=1