我正在寻找在Guzzle 6中检索请求总时间,就在一个简单的GET请求之后:
$client = new GuzzleHttp\Client();
$response = client->get('http://www.google.com/');
但是在文档中找不到任何关于那个的东西。任何的想法 ?
非常感谢。
在Guzzle 6.1.0中您可以使用'on_stats'请求选项来获取传输时间等。
更多信息可以在Request Options - on_stats找到
$client = new GuzzleHttp\Client();
$one = microtime(1);
$response = $client->get('http://www.google.com/');
$two = microtime(1);
echo 'Total Request time: '. ( $two - $one );
我有一个类似的问题,虽然它仍然是Guzzle 5.3。
见Guzzle 5.3 - Get request duration for asynchronous requests
也许在Guzzle6中收听一个事件并检索TransferInfo也可以帮到你。
这适用于同步和异步请求。