如何删除 PHP 中的 CURL 时间限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4858104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove CURL time limit in PHP?
提问by Sammy
I am running a rather long script that fetches the contents of a specified domain and parses the html before running a series of tests on said html. Anyway the script times out after a while. I tried putting this at the top of my page but still no luck:
我正在运行一个相当长的脚本,它在对所述 html 运行一系列测试之前获取指定域的内容并解析 html。无论如何脚本会在一段时间后超时。我试着把它放在我的页面顶部,但仍然没有运气:
set_time_limit(0);
Here is the error in question:
这是有问题的错误:
cURL error number:28
cURL error:Operation timed out after 10000 milliseconds with 316183 out of 6476018 bytes received
回答by profitphp
You need to set the amount of time curl gets to complete its operations with curl_setopt.
您需要使用 curl_setopt 设置 curl 完成其操作的时间。
The CURLOPT_TIMEOUT setting to be specific.
CURLOPT_TIMEOUT 设置要具体。
curl_setopt($ch, CURLOPT_TIMEOUT, 400); // the timeout in seconds
回答by Jonah
Use the CURLOPT_TIMEOUT
option in conjunction with curl_setopt()
.
将该CURLOPT_TIMEOUT
选项与 结合使用curl_setopt()
。
curl_setopt($curl, CURLOPT_TIMEOUT, 0); // zero waits indefinitely
set_time_limit()
only sets how long the script can run. The issue you're having is a cURL timout.
set_time_limit()
只设置脚本可以运行多长时间。您遇到的问题是 cURL 超时。
回答by deceze
Set CURLOPT_TIMEOUT
to a higher value.
设置CURLOPT_TIMEOUT
为更高的值。