bentools / guzzle-duration-middleware
A GuzzleHTTP Middleware that adds a X-Request-Duration header to all responses to monitor response times.
Installs: 55 182
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 5
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^6.0
Requires (Dev)
- phpunit/phpunit: @stable
- symfony/var-dumper: ^3.3
This package is auto-updated.
Last update: 2024-10-15 00:52:14 UTC
README
This package is a middleware for GuzzleHttp 6+ that helps you monitor the time between requests and responses.
Usage
require_once __DIR__ . '/vendor/autoload.php'; use BenTools\GuzzleHttp\Middleware\DurationHeaderMiddleware; use GuzzleHttp\Client; $client = new Client(); $middleware = new DurationHeaderMiddleware($headerName = 'X-Request-Duration'); // header name is optional, this is the default value $client->getConfig('handler')->push($middleware); $response = $client->get('http://httpbin.org/delay/1'); var_dump((float) $response->getHeaderLine('X-Request-Duration')); // 1.177
Installation
composer require bentools/guzzle-duration-middleware
Tests
./vendor/bin/phpunit