我想获得每个请求的转移时间。
如何使用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) {
});
答案 0 :(得分:1)
解决方案:
$responses = Pool::batch($httpClient, $requests, ['fulfilled' => function($response, $index) {
}, 'options' => ['on_stats' => function(TransferStats $stats) {
//..
}]]);