Guzzle 6 - 获取请求总时间

Ben*_*oth 9 php curl guzzle guzzle6

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

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

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

非常感谢.

Mic*_*ael 17

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

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

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


Mah*_*yfo 0

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