关于 php:guzzle6 中如何获取 Pool 请求的传输时间?

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();
foreach ($items as $request) {
    $requests[] = new Request(...);
}

$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) {
//..
}]]);


以上是关于 php:guzzle6 中如何获取 Pool 请求的传输时间?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>