Skip to content

Commit 3778f07

Browse files
committed
Ensure options set are used when make requests in parallel
1 parent 84201bc commit 3778f07

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Curl.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Curl {
44

55
private $_cookies = array();
66
private $_headers = array();
7+
private $_options = array();
78

89
private $_multi_parent = FALSE;
910
private $_multi_child = FALSE;
@@ -65,6 +66,12 @@ public function get($url_mixed, $data=array()) {
6566
}
6667
}
6768

69+
foreach ($this->curls as $ch) {
70+
foreach ($this->_options as $key => $value) {
71+
$ch->setOpt($key, $value);
72+
}
73+
}
74+
6875
do {
6976
$status = curl_multi_exec($curl_multi, $active);
7077
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
@@ -132,6 +139,7 @@ public function setCookie($key, $value) {
132139

133140
public function setOpt($option, $value, $_ch=NULL) {
134141
$ch = is_null($_ch) ? $this->curl : $_ch;
142+
$this->_options[$option] = $value;
135143
return curl_setopt($ch, $option, $value);
136144
}
137145

tests/run.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ public function testParallelRequests() {
298298
$this->assertTrue(substr($curl->curls['2']->response, - $len) === '/c/?foo=bar');
299299
}
300300

301+
public function testParallelSetOptions() {
302+
$curl = new Curl();
303+
$curl->setHeader('X-DEBUG-TEST', 'server');
304+
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
305+
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
306+
$curl->setOpt(CURLOPT_USERAGENT, 'useragent');
307+
$curl->complete(function($instance) {
308+
PHPUnit_Framework_Assert::assertTrue($instance->response === 'useragent');
309+
});
310+
$curl->get(array(
311+
Test::TEST_URL,
312+
), array(
313+
'key' => 'HTTP_USER_AGENT',
314+
));
315+
}
316+
301317
public function testSuccessCallback() {
302318
$success_called = FALSE;
303319
$error_called = FALSE;

0 commit comments

Comments
 (0)