bmancone / guzzle-stopwatch-middleware
Stopwatch Middleware for Guzzle.
Installs: 103 512
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.0|^7.0
- symfony/stopwatch: ^3.4|^4.0|^5.0|^6.0
Requires (Dev)
- mockery/mockery: ^1.3
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-11-29 04:14:44 UTC
README
Installation
composer require bmancone/guzzle-stopwatch-middleware
Usage
Requires an instance of Symfony\Component\Stopwatch\Stopwatch
.
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use Symfony\Component\Stopwatch\Stopwatch; Use Leadz\GuzzleHttp\Stopwatch\StopwatchMiddleware; // Create the default HandlerStack $stack = HandlerStack::create(); // Create the middleware $middleware = new StopwatchMiddleware(new Stopwatch()); // Push the Middleware to the stack $stack->push($middleware); // Create the client $client = new Client([ 'handler' => $stack ]); // Send the request $request = new Request('GET', 'https://en.wikipedia.org/wiki/Main_Page'); $response = $client->send($request); // Get the duration of the request printf('Request to [%s] took [%dms]', (string)$request->getUri(), $response->getHeaderLine('X-Duration'));
Symfony Profiler
If you are using Symfony, simply inject debug.stopwatch
(or use autowiring), this will add events to the profiler timeline.