PHP:默认 cURL 超时值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10308915/
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
PHP: Default cURL timeout value
提问by Raptor
What is the default PHP cURL timeout value? Can I obtain the value from coding?
默认的 PHP cURL 超时值是多少?我可以从编码中获得价值吗?
采纳答案by dtbarne
The defaults are as follows:
默认值如下:
- CURLOPT_FTP_RESPONSE_TIMEOUT: Indefinite
- CURLOPT_TIMEOUT: Indefinite
- CURLOPT_TIMEOUT_MS: Indefinite
- CURLOPT_CONNECTTIMEOUT: 300 seconds
- CURLOPT_CONNECTTIMEOUT_MS: Indefinite
- CURLOPT_ACCEPTTIMEOUT_MS: 60 seconds
- CURLOPT_FTP_RESPONSE_TIMEOUT:无限期
- CURLOPT_TIMEOUT:无限期
- CURLOPT_TIMEOUT_MS:不确定
- CURLOPT_CONNECTTIMEOUT:300 秒
- CURLOPT_CONNECTTIMEOUT_MS:不定
- CURLOPT_ACCEPTTIMEOUT_MS:60 秒
Previous answer (for reference):
上一个答案(供参考):
My understanding is that CURL obeys the default_socket_timeout unless overriden with CURLOPT_TIMEOUT/CURLOPT_CONNECTTIMEOUT.
我的理解是 CURL 遵守 default_socket_timeout 除非被CURLOPT_TIMEOUT/覆盖CURLOPT_CONNECTTIMEOUT。
$socket_timeout = ini_get('default_socket_timeout'); // timeout in seconds
回答by Michael Dowling
It depends on which timeout setting you're talking about.
这取决于您所谈论的超时设置。
cURL offers various options specific to connection timeout settings. Some of these options have a set limit, while others allow transfers to take an indefinite amount of time. In order to understand which values have default settings and which do not, you need to look at libcurl's curl_easy_setopt()function: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
cURL 提供了各种特定于连接超时设置的选项。其中一些选项有一定的限制,而另一些选项则允许无限期地进行转账。为了了解哪些值具有默认设置,哪些没有,您需要查看 libcurl 的curl_easy_setopt()函数:http: //curl.haxx.se/libcurl/c/curl_easy_setopt.html
libcurl lists the following connection timeout specific settings:
libcurl 列出了以下连接超时特定设置:
- CURLOPT_FTP_RESPONSE_TIMEOUT: No default (indefinite)
- CURLOPT_TIMEOUT: No default (indefinite)
- CURLOPT_TIMEOUT_MS: No default (indefinite)
- CURLOPT_CONNECTTIMEOUT: Defaults to 300 seconds
- CURLOPT_CONNECTTIMEOUT_MS: No default
- CURLOPT_ACCEPTTIMEOUT_MS: Defaults to 60000 ms
- CURLOPT_FTP_RESPONSE_TIMEOUT:无默认值(不确定)
- CURLOPT_TIMEOUT:无默认值(不确定)
- CURLOPT_TIMEOUT_MS:无默认值(不确定)
- CURLOPT_CONNECTTIMEOUT:默认为 300 秒
- CURLOPT_CONNECTTIMEOUT_MS:无默认值
- CURLOPT_ACCEPTTIMEOUT_MS:默认为 60000 毫秒
The PHP source code does not override any of the above default settings: https://github.com/php/php-src/blob/master/ext/curl/interface.c. The only somewhat related parameter that the PHP bindings override is CURLOPT_DNS_CACHE_TIMEOUT, changing the default value from 60 seconds to 120 seconds: https://github.com/php/php-src/blob/a0e3ca1c986681d0136ce4550359ecee2826a80c/ext/curl/interface.c#L1926
PHP 源代码不会覆盖任何上述默认设置:https: //github.com/php/php-src/blob/master/ext/curl/interface.c。PHP 绑定覆盖的唯一相关参数是CURLOPT_DNS_CACHE_TIMEOUT,将默认值从 60 秒更改为 120 秒:https: //github.com/php/php-src/blob/a0e3ca1c986681d0136ce4550359ecee2826a80c/ext/curl/interface.c#L1926
One of the other answers stated that PHP will set CURLOPT_TIMEOUTto the value specified in the default_socket_timeoutini setting. I was not able to find anything in the PHP source code to back up this claim, and I was unable to trigger a cURL timeout by downloading a very large file with a default_socket_timeoutsetting of 1 second.
其他答案之一指出 PHP 将设置CURLOPT_TIMEOUT为default_socket_timeoutini 设置中指定的值。我无法在 PHP 源代码中找到任何内容来支持此声明,并且无法通过下载一个default_socket_timeout设置为 1 秒的非常大的文件来触发 cURL 超时。
回答by tosin
None in libcurl. http://curl.haxx.se/mail/lib-2003-05/0097.html
libcurl 中没有。http://curl.haxx.se/mail/lib-2003-05/0097.html

