Blackfire provides a Guzzle integration that eases profiling HTTP sub-requests as used in a microservices-oriented infrastructure.
Supports comes as a middleware that you need to register explicitly.
First, add the Blackfire SDK to your project:
composer require blackfire/php-sdk
Then, register the Guzzle middleware:
1 2 3 4 5 6 7 8 9
use GuzzleHttp\Client as GuzzleClient; use Blackfire\Client as BlackfireClient; use Blackfire\ClientConfiguration; use Blackfire\Bridge\Guzzle\Middleware as BlackfireMiddleware; $blackfire = new BlackfireClient(new ClientConfiguration($clientId, $clientToken)); $guzzle = new GuzzleClient(); $guzzle->getConfig('handler')->push(BlackfireMiddleware::create($blackfire), 'blackfire');
Now, everytime you profile your application without aggregation, sub-requests handled by Guzzle will be profiled.
Be aware that HTTP sub-requests profiling is not compatible with aggregation.
Therefore you should disable aggregation when expecting such behavior;
Use the relevant checkbox for the companion or add
--samples=1 for the CLI.