Skip to content

bmancone/guzzle-stopwatch-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guzzle middleware to time requests

Author Latest Version Build Status

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.

About

Guzzle 6 middleware to time requests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages