CURLOPT_TIMEOUT 在 php/windows 中不起作用?
我在 XAMPP 和 Windows 上使用以下函数。但我不断收到“致命错误:超出最大执行时间 30 秒”
有任何提示吗?
function is_404($url) {
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_TIMEOUT,10);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT,10);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
/* If the document has loaded successfully without any redirection or error */
if ($httpCode >= 200 && $httpCode < 300) {
return false;
} else {
return true;
}
}
I am using the following function with XAMPP and Windows. But I keep getting "Fatal error: Maximum execution time of 30 seconds exceeded "
Any tips?
function is_404($url) {
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_TIMEOUT,10);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT,10);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
/* If the document has loaded successfully without any redirection or error */
if ($httpCode >= 200 && $httpCode < 300) {
return false;
} else {
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 libcurl 版本可能存在错误。也许您可以尝试升级到更新的版本?
您可以在该系统上(在特定 URL 上)运行curl 命令行工具来调试发生的情况吗?如果可以的话,使用 -v 或 --trace-ascii 选项对于准确显示curl 的作用和不作用应该很有价值。
您的代码应该像编写的那样工作。
There might be a bug in your version of libcurl. Perhaps you can try to upgrade to a more recent version?
Can you run the curl command line tool on that system (on the particular URL) to debug what happens? If you can, using the -v or --trace-ascii options should be valuable to show exactly what curl does and doesn't.
Your code is supposed to work just as written.