Ensure options set are used when make requests in parallel

This commit is contained in:
Zach Borboa
2013-12-28 23:22:36 -08:00
parent 84201bcaaa
commit 3778f070cb
2 changed files with 24 additions and 0 deletions
+8
View File
@@ -4,6 +4,7 @@ class Curl {
private $_cookies = array();
private $_headers = array();
private $_options = array();
private $_multi_parent = FALSE;
private $_multi_child = FALSE;
@@ -65,6 +66,12 @@ class Curl {
}
}
foreach ($this->curls as $ch) {
foreach ($this->_options as $key => $value) {
$ch->setOpt($key, $value);
}
}
do {
$status = curl_multi_exec($curl_multi, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
@@ -132,6 +139,7 @@ class Curl {
public function setOpt($option, $value, $_ch=NULL) {
$ch = is_null($_ch) ? $this->curl : $_ch;
$this->_options[$option] = $value;
return curl_setopt($ch, $option, $value);
}
+16
View File
@@ -298,6 +298,22 @@ class CurlTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(substr($curl->curls['2']->response, - $len) === '/c/?foo=bar');
}
public function testParallelSetOptions() {
$curl = new Curl();
$curl->setHeader('X-DEBUG-TEST', 'server');
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
$curl->setOpt(CURLOPT_USERAGENT, 'useragent');
$curl->complete(function($instance) {
PHPUnit_Framework_Assert::assertTrue($instance->response === 'useragent');
});
$curl->get(array(
Test::TEST_URL,
), array(
'key' => 'HTTP_USER_AGENT',
));
}
public function testSuccessCallback() {
$success_called = FALSE;
$error_called = FALSE;