Last active
November 6, 2019 08:30
-
-
Save nicolas-grekas/a7ba7db5126b62c8f98f1bbf6135d9af to your computer and use it in GitHub Desktop.
Symfony HttpClient benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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