How to get transfer time for Pool requests in guzzle6?
我想获取每个请求的传输时间。
如何将 on_stats 选项用于异步请求?
http://docs.guzzlephp.org/en/latest/request-options.html#on-stats
我的代码:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php
use GuzzleHttp\\{Pool, Client}; use GuzzleHttp\\Psr7\\{ Request, Response }; $httpClient = new Client(); $responses = Pool::batch($httpClient, $requests, [‘fulfilled’ => function($response, $index) { }); |
- 检查这个例子,看看它是否有帮助.. guzzle.readthedocs.io/en/latest/request-options.html#on-stat??s
- @Nevermore 我不知道如何在 PSR7 请求中使用它
- @iilexial 检查这是否有帮助.. docs.guzzlephp.org/en/latest/psr7.html
- @Nevermore 我知道这个页面。此页面上没有带有 on_stats 选项的示例。
解决方案:
1
2 3 4 5 |
$responses = Pool::batch($httpClient, $requests, [‘fulfilled’ => function($response, $index) {
}, ‘options’ => [‘on_stats’ => function(TransferStats $stats) { |
来源:https://www.codenong.com/42533232/