scratch – Blame information for rev 87

Subversion Repositories:
Rev:
Rev Author Line No. Line
87 office 1 <?php
2 /*
3 * Runs a performance test against the node.js server for both serial and
4 * parallel requests. Requires PHP 5.5 or greater.
5 *
6 * # Basic usage
7 * make perf
8 * # With custom options
9 * REQUESTS=100 PARALLEL=5000 make perf
10 */
11  
12 require __DIR__ . '/bootstrap.php';
13  
14 use GuzzleHttp\Client;
15 use GuzzleHttp\Tests\Server;
16  
17 // Wait until the server is responding
18 Server::wait();
19  
20 // Get custom make variables
21 $total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000;
22 $parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 25;
23  
24 $client = new Client(['base_url' => Server::$url]);
25  
26 $t = microtime(true);
27 for ($i = 0; $i < $total; $i++) {
28 $client->get('/guzzle-server/perf');
29 }
30 $totalTime = microtime(true) - $t;
31 $perRequest = ($totalTime / $total) * 1000;
32 printf("Serial: %f (%f ms / request) %d total\n",
33 $totalTime, $perRequest, $total);
34  
35 // Create a generator used to yield batches of requests to sendAll
36 $reqs = function () use ($client, $total) {
37 for ($i = 0; $i < $total; $i++) {
38 yield $client->createRequest('GET', '/guzzle-server/perf');
39 }
40 };
41  
42 $t = microtime(true);
43 $client->sendAll($reqs(), ['parallel' => $parallel]);
44 $totalTime = microtime(true) - $t;
45 $perRequest = ($totalTime / $total) * 1000;
46 printf("Parallel: %f (%f ms / request) %d total with %d in parallel\n",
47 $totalTime, $perRequest, $total, $parallel);