|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-25 13:21 UTC] jani@php.net
[2007-11-02 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
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' }