1

好吧,这真的很奇怪。当我向本地主机发出请求时(大约需要 1-2 毫秒),curl 需要更长的时间。它似乎取决于超时(ConnectionTimeout / normaltimeout 的最低值)。

所有请求都成功

  • 当 Timeout_Ms = 5 时,curl 恢复的时间约为 1 Ms。
  • 当 Timeout_Ms = 50 时,curl 恢复的时间约为 4 Ms。
  • 当 Timeout_Ms = 500 时,卷曲恢复的时间约为 250 毫秒。
  • 当 Timeout_Ms = 1000 时,curl 恢复的时间约为 500 Ms。
  • 当 Timeout_Ms = 1500 时,curl 恢复的时间约为 750 Ms。
  • 当 Timeout_Ms > 2000 时,curl 恢复的时间约为 1000 Ms。

因此,当将超时设置为高时,请求总是需要 1 秒。使用 curl_multi 时,时间也增加了 1 秒,但我做了多少请求并不重要。

我有两个要求:

  • 一个需要 5 秒 -> 6 秒后完成
  • 第二个需要 10 秒 -> 11 秒后完成
4

1 回答 1

0

这很可能是因为服务器希望保持连接打开以供可能的进一步请求。将Connection-header 设置为close. 参见例如http://php.net/curl.constants.php#76914

$header = array("Connection: close");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
于 2012-01-03T19:28:33.330 回答