Skip to content

Instantly share code, notes, and snippets.

@nicolas-grekas
Last active November 6, 2019 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas-grekas/a7ba7db5126b62c8f98f1bbf6135d9af to your computer and use it in GitHub Desktop.
Save nicolas-grekas/a7ba7db5126b62c8f98f1bbf6135d9af to your computer and use it in GitHub Desktop.
Symfony HttpClient benchmarks
<?php
require 'vendor/autoload.php';
$start = microtime(true);
/* GUZZLE * /
$client = new GuzzleHttp\Client();
$promises = [];
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$promises[] = $client->sendAsync($request);
}
foreach ($promises as $promise) {
$promise->wait()->getBody()->getContents();
echo '.';
}
/**/
/* HTTPLUG CURL * /
$client = new Http\Client\Curl\Client();
$promises = [];
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$promises[] = $client->sendAsyncRequest($request);
}
foreach ($promises as $promise) {
$promise->wait()->getBody()->getContents();
echo '.';
}
/**/
/* SYMFONY */
$client = new Symfony\Component\HttpClient\CurlHttpClient();
$responses = [];
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$responses[] = $client->request('GET', $url);
}
foreach ($responses as $response) {
$response->getContent();
echo '.';
}
/**/
echo sprintf("\n\n%.3f\n", microtime(true) - $start);
<?php
require 'vendor/autoload.php';
$start = microtime(true);
/* GUZZLE * /
$client = new GuzzleHttp\Client();
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$client->send($request)->getBody()->getContents();
echo '.';
}
/**/
/* HTTPLUG SOCKET * /
$client = new Http\Client\Socket\Client();
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$client->sendRequest($request)->getBody()->getContents();
echo '.';
}
/**/
/* SYMFONY * /
$client = new Symfony\Component\HttpClient\NativeHttpClient();
for ($i = 0; $i < 379; ++$i) {
$url = "https://http2.akamai.com/demo/tile-$i.png";
$client->request('GET', $url)->getContent();
echo '.';
}
/**/
echo sprintf("\n\n%.3f\n", microtime(true) - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment