From: robert dot reichel at boboton dot com
Operating system: Windows XP
PHP version: 5.2.4
PHP Bug Type: cURL related
Bug description: curl_multi_exec does not report errors
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 bug report at http://bugs.php.net/?id=43077&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43077&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43077&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43077&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43077&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43077&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43077&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43077&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43077&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43077&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43077&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43077&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43077&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43077&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43077&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43077&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43077&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43077&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43077&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43077&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43077&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43077&r=mysqlcfg