bmancone / guzzle-stopwatch-middleware
Guzzle 的计时器中间件。
v1.0.2
2022-10-29 13:45 UTC
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-08-29 03:31:31 UTC
README
安装
composer require bmancone/guzzle-stopwatch-middleware
使用
需要 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 分析器
如果您使用的是 Symfony,只需注入 debug.stopwatch
(或使用自动装配),这将向分析器时间线添加事件。