mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Process multicurl requests in ascending numerical order.
Previously, multicurl requests were added to the end and removed from the end. Requests are now added to the end and removed from the beginning. Using array_shift() will be slower than array_pop(). Before using "array_push()" + array_pop(): 1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 After using "array_push()" + array_shift(): 1 1 2 1 2 3 1 2 3 4 2 3 4 3 4 4
This commit is contained in:
@@ -641,7 +641,7 @@ class MultiCurl
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $concurrency; $i++) {
|
||||
$this->initHandle(array_pop($this->curls));
|
||||
$this->initHandle(array_shift($this->curls));
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -662,7 +662,7 @@ class MultiCurl
|
||||
|
||||
// Start a new request before removing the handle of the completed one.
|
||||
if (count($this->curls) >= 1) {
|
||||
$this->initHandle(array_pop($this->curls));
|
||||
$this->initHandle(array_shift($this->curls));
|
||||
}
|
||||
curl_multi_remove_handle($this->multiCurl, $ch->curl);
|
||||
|
||||
|
||||
@@ -2486,4 +2486,22 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($sequential_id, $instance->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAscendingNumericalOrder()
|
||||
{
|
||||
$counter = 0;
|
||||
$multi_curl = new MultiCurl();
|
||||
$multi_curl->setConcurrency(1);
|
||||
$multi_curl->complete(function ($instance) use (&$counter) {
|
||||
$sequential_id = $instance->getOpt(CURLOPT_POSTFIELDS);
|
||||
PHPUnit_Framework_Assert::assertEquals($counter, $sequential_id);
|
||||
$counter++;
|
||||
});
|
||||
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$multi_curl->addPost(Test::TEST_URL, $i);
|
||||
}
|
||||
|
||||
$multi_curl->start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user