bentools/guzzle-duration-middleware

一个 GuzzleHttp 中间件,它将 X-Request-Duration 标头添加到所有响应中,以监控响应时间。

1.0 2017-06-09 09:48 UTC

This package is auto-updated.

Last update: 2024-09-15 00:44:01 UTC


README

本包是 GuzzleHttp 6+ 的中间件,有助于您监控请求和响应之间的时间。

使用方法

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

安装

composer require bentools/guzzle-duration-middleware

测试

./vendor/bin/phpunit