php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43077 curl_multi_exec does not report errors
Submitted: 2007-10-23 08:08 UTC Modified: 2007-11-02 01:00 UTC
From: robert dot reichel at boboton dot com Assigned:
Status: No Feedback Package: cURL related
PHP Version: 5.2.4 OS: Windows XP
Private report: No CVE-ID: None
 [2007-10-23 08:08 UTC] 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'
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-25 13:21 UTC] jani@php.net
You should be using curl_multi_info_read() instead: http://php.net/curl_multi_info_read

 [2007-11-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 05:01:27 2024 UTC