mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-05 23:38:22 +00:00
Fix #61: Ensure curl error is correctly set when making GET calls in parallel
This commit is contained in:
+2
-5
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user