Guzzle 6 - 获取请求总时间

问题描述 投票:7回答:3

我正在寻找在Guzzle 6中检索请求总时间,就在一个简单的GET请求之后:

$client = new GuzzleHttp\Client();
$response = client->get('http://www.google.com/');

但是在文档中找不到任何关于那个的东西。任何的想法 ?

非常感谢。

php curl guzzle guzzle6
3个回答
16
投票

在Guzzle 6.1.0中您可以使用'on_stats'请求选项来获取传输时间等。

更多信息可以在Request Options - on_stats找到

https://github.com/guzzle/guzzle/releases/tag/6.1.0


1
投票
$client = new GuzzleHttp\Client();
$one = microtime(1);
$response = $client->get('http://www.google.com/');
$two = microtime(1);
echo 'Total Request time: '. ( $two - $one );

-1
投票

我有一个类似的问题,虽然它仍然是Guzzle 5.3。

Guzzle 5.3 - Get request duration for asynchronous requests

也许在Guzzle6中收听一个事件并检索TransferInfo也可以帮到你。

这适用于同步和异步请求。

© www.soinside.com 2019 - 2024. All rights reserved.