3 class pool
extends HttpRequestPool
{
7 static function fetch($url, $n, $c, $e) {
12 $pool->enableEvents($e);
14 for ($i = 0; $i < $c; ++
$i) {
19 } catch (Exception
$ex) {
26 request
::init($this, $this->url
)->id
= $this->cnt
--;
31 class request
extends HttpRequest
{
37 static function init(pool
$pool, $url) {
38 $r = new request($url);
46 $this->pool
->detach($this);
53 fprintf(STDERR
, "Usage: %s -u <URL> -n <requests> -c <concurrency> -e (use libevent)\n", $argv[0]);
54 fprintf(STDERR
, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n");
58 isset($argv) or $argv = $_SERVER['argv'];
59 defined('STDERR') or define('STDERR', fopen('php://stderr', 'w'));
61 $opts = getopt("u:c:n:e");
62 isset($opts["u"]) or $opts["u"] = "http://localhost/";
63 isset($opts["c"]) or $opts["c"] = 10;
64 isset($opts["n"]) or $opts["n"] = 1000;
66 http_parse_message(http_head($opts["u"]))->responseCode
== 200 or usage();
68 $time = microtime(true);
69 pool
::fetch($opts["u"], $opts["n"], $opts["c"], isset($opts["e"]));
70 printf("\n> %10.6fs\n", microtime(true)-$time);
72 request
::$counter == $opts["n"] or printf("\nOnly %d finished\n", request
::$counter);