本文介绍了curl超时小于1000ms总是失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码总是失败(即 $ result
是布尔 false
):
This code always fails (i.e., $result
is Boolean false
):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$curl_version = curl_version();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 999);
$result = curl_exec($ch);
curl_close($ch);
此代码总是成功的(即 $ result
是包含标题的字符串):
This code always succeeds (i.e., $result
is a string containing the header):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$curl_version = curl_version();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 1000);
$result = curl_exec($ch);
curl_close($ch);
唯一的区别是我已将超时从999ms更改为1000ms。
The only difference is that I've changed the timeout from 999ms to 1000ms.
这是我错过的连接超时的文档中的curl或某种最低限度的错误。这是什么?我的钱是后者。
This must be either a bug in curl or some sort of minimum in the documentation for connection timeouts that I missed. Which is it? My money is on the latter.
推荐答案
来自:
这篇关于curl超时小于1000ms总是失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!