关于 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) {

});


解决方案:

1
2
3
4
5
$responses = Pool::batch($httpClient, $requests, ['fulfilled' => function($response, $index) {

}, 'options' => ['on_stats' => function(TransferStats $stats) {
//..
}]]);