Created
August 13, 2010 03:59
-
-
Save nowelium/522243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// concurrent http request safe check: (PubSub tests) | |
// | |
// depends {HttpRequest, HttpRequestPool} => pecl_http | |
// | |
class MyRequest extends HttpRequest { | |
protected $id; | |
protected $time; | |
public function __construct($id){ | |
$this->id = $id; | |
$this->time = microtime(true); | |
parent::__construct('http://localhost:8080/api/' . $id, HTTP_METH_GET); | |
} | |
public function getId(){ | |
return $this->id; | |
} | |
public function getTime(){ | |
return $this->time; | |
} | |
public function getDiff(){ | |
return microtime(true) - $this->time; | |
} | |
} | |
$pool = new HttpRequestPool; | |
$pool->attach(new MyRequest('a')); | |
$pool->attach(new MyRequest('b')); | |
$pool->attach(new MyRequest('c')); | |
$pool->attach(new MyRequest('d')); | |
$pool->attach(new MyRequest('e')); | |
$pool->attach(new MyRequest('f')); | |
$pool->send(); | |
foreach ($pool->getFinishedRequests() as $req){ | |
echo 'finish: ', $req->getId(), ':', $req->getResponseBody(), ':', $req->getDiff(), PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment