如何在guzzle6中获取Pool请求的传输时间?

时间:2017-03-01 13:36:31

标签: php guzzle guzzle6

我想获得每个请求的转移时间。 如何使用on_stats选项进行异步请求?
http://docs.guzzlephp.org/en/latest/request-options.html#on-stats

我的代码:

<?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 个答案:

答案 0 :(得分:1)

解决方案:

$responses = Pool::batch($httpClient, $requests, ['fulfilled' => function($response, $index) {

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