【问题标题】:Recording time of post and result记录时间和结果
【发布时间】:2013-02-22 12:40:46
【问题描述】:

我正在使用 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);

【问题讨论】:

    标签: php post curl


    【解决方案1】:
    curl_getinfo ( resource $ch [, int $opt = 0 ] )
    

    http://php.net/manual/en/function.curl-getinfo.php请查看

    【讨论】:

    • 连接时间是您所寻找的
    【解决方案2】:

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

    $start_ts = time();
    
    // code that takes some time goes here
    
    echo "This code took" . (time() - $start_ts) .' seconds to execute";
    

    使用此方法,您只能以秒为单位测量持续时间。 time() 函数返回 epoch timestamp(自 1970 年 1 月 1 日以来的秒数)。

    要获得更准确的测量结果,您可能需要查看 PHP 的 microtime() function

    【讨论】:

      【解决方案3】:

      您可能想试试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
      

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 2015-10-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-10-19
          相关资源
          最近更新 更多