3
* Runs a performance test against the node.js server for both serial and
4
* parallel requests. Requires PHP 5.5 or greater.
8
* # With custom options
9
* REQUESTS=100 PARALLEL=5000 make perf
12
require __DIR__ . '/bootstrap.php';
14
use GuzzleHttp\Client;
15
use GuzzleHttp\Tests\Server;
17
// Wait until the server is responding
20
// Get custom make variables
21
$total = isset($_SERVER['REQUESTS']) ? $_SERVER['REQUESTS'] : 1000;
22
$parallel = isset($_SERVER['PARALLEL']) ? $_SERVER['PARALLEL'] : 25;
24
$client = new Client(['base_url' => Server::$url]);
27
for ($i = 0; $i < $total; $i++) {
28
$client->get('/guzzle-server/perf');
30
$totalTime = microtime(true) - $t;
31
$perRequest = ($totalTime / $total) * 1000;
32
printf("Serial: %f (%f ms / request) %d total\n",
33
$totalTime, $perRequest, $total);
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');
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);