此代码总是失败(即,$result
是 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
是包含标头的字符串):
$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);
唯一的区别是我将超时时间从 999 毫秒更改为 1000 毫秒。
这必须是 curl 中的错误,或者是我错过的连接超时文档中的某种最小值。它是哪一个?我的钱是后者。