1

我正在使用 cURL 发布并接收回复。无论如何,我可以记录它发送到我收到响应的时间吗?这就是我的帖子和响应代码的样子。

$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataBeingPassed);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
4

4 回答 4

0
curl_getinfo ( resource $ch [, int $opt = 0 ] )

http://php.net/manual/en/function.curl-getinfo.php请检查一下

于 2013-02-22T12:43:32.613 回答
0

您可以只保存请求之前的时间并将其与请求之后的时间进行比较 -

$start_ts = time();

// code that takes some time goes here

echo "This code took" . (time() - $start_ts) .' seconds to execute";

使用这种方法,您只能以秒为单位测量持续时间。该time()函数返回一个纪元时间戳(自 1970 年 1 月 1 日以来的秒数)。

对于一些更准确的测量,您可能需要查看 PHP 的microtime()函数

于 2013-02-22T12:43:59.510 回答
0

您可能想尝试一下curl_getinfo

CURLINFO_TOTAL_TIME - Total transaction time in seconds for last transfer
CURLINFO_NAMELOOKUP_TIME - Time in seconds until name resolving was complete
CURLINFO_CONNECT_TIME - Time in seconds it took to establish the connection
CURLINFO_PRETRANSFER_TIME - Time in seconds from start until just before file transfer begins
CURLINFO_STARTTRANSFER_TIME - Time in seconds until the first byte is about to be transferred
于 2013-02-22T12:44:21.123 回答
0

您可以为此使用 curl_getinfo()。参考这个

http://www.php.net/manual/en/function.curl-getinfo.php

于 2013-02-22T12:53:17.040 回答