How do we track request time with Guzzle and Guzzle Bundle?

With confidence I can say that requests are not the fastest part of any application and for “unknown” reasons, one day you will want to check the time it takes and it will spoil your day.

Let’s create a guzzle client, that will be used, to perform request:

use GuzzleHttp\Client;

$client = new Client();

And just add on_stats option to the request:

$client->request('GET', '', [
'on_stats' => function (TransferStats $stats) {
// Estimated time the request was being transferred
// $stats->getTransferTime();

Your callback will be called by guzzle and useful information will be passed through TransferStats object.

Things become even easier if you’re using Symfony:

Step 1: Install GuzzleBundle

composer require eightpoints/guzzle-bundle

Step 2: Configure client

base_url: ""

Step 3: Do a request


Step 4: Track request time in Profiler

Guzzle Bundle tracks the time of all requests and shows all the information in a convenient form.

Read more here: