Fix #400: Use sequential ids to allow for ordered post processing

This commit is contained in:
Zach Borboa
2016-10-14 19:50:57 -07:00
parent 5763a7c60f
commit 5cb8223c47
2 changed files with 24 additions and 0 deletions
+3
View File
@@ -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);
}
}
}