3 class pool
extends HttpRequestPool
{
7 static function fetch($url, $n, $c, $e, $p) {
12 $pool->enablePipelining($p);
13 $pool->enableEvents($e);
15 for ($i = 0; $i < $c; ++
$i) {
20 } catch (Exception
$ex) {
27 request
::init($this, $this->url
)->id
= $this->cnt
--;
36 class request
extends HttpRequest
{
42 static function init(pool
$pool, $url) {
43 #printf("init %d\n", $pool->cnt());
44 $r = new request($url);
51 #printf("left %d\n", count($this->pool));
52 #printf("done %d\n", $this->id);
54 $this->pool
->detach($this);
61 fprintf(STDERR
, "Usage: %s -u <URL> -n <requests> -c <concurrency> -e (use libevent) -p (use pipelining)\n", $argv[0]);
62 fprintf(STDERR
, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n");
66 isset($argv) or $argv = $_SERVER['argv'];
67 defined('STDERR') or define('STDERR', fopen('php://stderr', 'w'));
69 $opts = getopt("u:c:n:ep"); #var_dump($opts);
70 isset($opts["u"]) or $opts["u"] = "http://localhost/";
71 isset($opts["c"]) or $opts["c"] = 10;
72 isset($opts["n"]) or $opts["n"] = 500;
74 http_parse_message(http_head($opts["u"]))->responseCode
== 200 or usage();
76 $time = microtime(true);
77 pool
::fetch($opts["u"], $opts["n"], $opts["c"], isset($opts["e"]), isset($opts["p"]));
78 printf("\n> %10.6fs\n", microtime(true)-$time);
80 printf("\nMemory usage: %s/%s\n", number_format(memory_get_usage()),number_format(memory_get_peak_usage()));
82 if (request
::$counter != $opts["n"]) {
83 printf("\nOnly %d finished\n", request
::$counter);