Fix #61: Ensure curl error is correctly set when making GET calls in parallel

This commit is contained in:
Zach Borboa
2014-05-28 10:08:02 -07:00
parent 632511b5de
commit eefd6593fa
2 changed files with 19 additions and 5 deletions
+2 -5
View File
@@ -82,9 +82,8 @@ class Curl
$status = curl_multi_exec($curl_multi, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
//getting curl_error_codes of children
while (($info_array = curl_multi_info_read($curl_multi)) !== FALSE) {
if ($info_array['msg'] !== CURLMSG_DONE) {
while (!($info_array = curl_multi_info_read($curl_multi)) === false) {
if (!($info_array['msg'] === CURLMSG_DONE)) {
continue;
}
foreach ($this->curls as $ch) {
@@ -400,8 +399,6 @@ class Curl
if ($ch->multi_child) {
$ch->response = curl_multi_getcontent($ch->curl);
//curl_errno() cannot be used with multi child handle
//Alternatively, use curl_multi_info_read() on parent handle (see get())
} else {
$ch->response = curl_exec($ch->curl);
$ch->curl_error_code = curl_errno($ch->curl);
+17
View File
@@ -674,6 +674,23 @@ class CurlTest extends PHPUnit_Framework_TestCase
$this->assertTrue(substr($curl->curls['2']->response, - $len) === '/c/?foo=bar');
}
public function testParallelRequestErrors()
{
$test = new Test();
$curl = $test->curl;
$curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 4000);
$curl->complete(function ($instance) use (&$success_called, &$error_called, &$complete_called) {
PHPUnit_Framework_Assert::assertTrue($instance->error);
PHPUnit_Framework_Assert::assertTrue($instance->curl_error);
PHPUnit_Framework_Assert::assertTrue($instance->curl_error_code === CURLE_OPERATION_TIMEOUTED);
});
$curl->get(array(
Test::ERROR_URL . 'a/',
Test::ERROR_URL . 'b/',
Test::ERROR_URL . 'c/',
));
}
public function testParallelSetOptions()
{
$test = new Test();