3 function usage($e = null) {
6 fprintf(STDERR
, "ERROR: %s\n\n", $e);
8 fprintf(STDERR
, "Usage: %s -u <URL> -n <requests> -c <concurrency> [-p (enable pipelining)] [-e (use libevent)]\n", $argv[0]);
9 fprintf(STDERR
, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n");
13 function push($client, $url, &$n) {
15 $req = new http\Client\
Request("GET", $url);
16 $client->enqueue($req, function($response) use ($client, $req, $url, &$n) {
17 global $count; ++
$count;
18 push($client, $url, $n);
19 return true; // dequeue
24 isset($argv) or $argv = $_SERVER['argv'];
25 defined('STDERR') or define('STDERR', fopen('php://stderr', 'w'));
27 $opts = getopt("u:c:n:e");
28 isset($opts["u"]) or $opts["u"] = "http://localhost/";
29 isset($opts["c"]) or $opts["c"] = 10;
30 isset($opts["n"]) or $opts["n"] = 1000;
34 $time = microtime(true);
36 $client = new http\Client
;
38 $client->enablePipelining($opts["p"]===false);
39 $client->enableEvents($opts["e"]===false);
41 for ($i = 0, $x = $opts["n"]; $i < $opts["c"]; ++
$i) {
42 push($client, $opts["u"], $x);
47 } catch (Exception
$e) {
51 printf("\n> %10.6fs (%3.2fM)\n", microtime(true)-$time, memory_get_peak_usage(true)/1024/1024);
53 $count == $opts["n"] or printf("\nOnly %d finished\n", $count);