Merge pull request #401 from zachborboa/master

Use sequential ids
This commit is contained in:
Zach Borboa
2016-10-14 20:23:22 -07:00
committed by GitHub
4 changed files with 26 additions and 2 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ if (!is_website_url($url)) {
```bash
# Attacker.
$ curl https://www.example.com/upload_photo.php --data "photo=@/etc/password"
$ curl https://www.example.com/upload_photo.php --data "photo=@/etc/passwd"
```
```php
+1 -1
View File
@@ -30,7 +30,7 @@ $multi_curl->complete(function ($instance) use (&$complete) {
$limit = 1000;
for ($i = 0; $i < $limit; $i++) {
$url = $urls[mt_rand(0, count($urls) - 1)];
$instance = $multi_curl->addGet($url);
$multi_curl->addGet($url);
}
$multi_curl->start();
+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);
}
}
}