mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Fix #400: Use sequential ids to allow for ordered post processing
This commit is contained in:
@@ -11,6 +11,7 @@ class MultiCurl
|
||||
private $activeCurls = array();
|
||||
private $isStarted = false;
|
||||
private $concurrency = 25;
|
||||
private $nextCurlId = 0;
|
||||
|
||||
private $beforeSendFunction = null;
|
||||
private $successFunction = null;
|
||||
@@ -736,6 +737,8 @@ class MultiCurl
|
||||
*/
|
||||
private function queueHandle($curl)
|
||||
{
|
||||
// Use sequential ids to allow for ordered post processing.
|
||||
$curl->id = $this->nextCurlId++;
|
||||
$this->curls[$curl->id] = $curl;
|
||||
}
|
||||
|
||||
|
||||
@@ -2420,4 +2420,25 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
|
||||
$multi_curl->addCurl($curl);
|
||||
$multi_curl->start();
|
||||
}
|
||||
|
||||
public function testSequentialId()
|
||||
{
|
||||
$completed = array();
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
$multi_curl->complete(function ($instance) use (&$completed) {
|
||||
$completed[] = $instance;
|
||||
});
|
||||
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$multi_curl->addPost(Test::TEST_URL, $i);
|
||||
}
|
||||
|
||||
$multi_curl->start();
|
||||
|
||||
foreach ($completed as $instance) {
|
||||
$sequential_id = $instance->getOpt(CURLOPT_POSTFIELDS);
|
||||
$this->assertEquals($sequential_id, $instance->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user