70

What is the default PHP cURL timeout value? Can I obtain the value from coding?

Tot Zam
  • 8,406
  • 10
  • 51
  • 76
Raptor
  • 53,206
  • 45
  • 230
  • 366

3 Answers3

101

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

libcurl lists the following connection timeout specific settings:

  • 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

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

One of the other answers stated that PHP will set CURLOPT_TIMEOUT to the value specified in the default_socket_timeout ini 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_timeout setting of 1 second.

Michael Dowling
  • 5,098
  • 4
  • 32
  • 28
41

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

Previous answer (for reference):

My understanding is that CURL obeys the default_socket_timeout unless overriden with CURLOPT_TIMEOUT/CURLOPT_CONNECTTIMEOUT.

$socket_timeout = ini_get('default_socket_timeout'); // timeout in seconds
dtbarne
  • 8,110
  • 5
  • 43
  • 49
  • 8
    Can you back this up? I couldn't find anything to prove this in the PHP curl bindings (https://github.com/php/php-src/blob/master/ext/curl/interface.c). I also tried setting my `default_socket_timeout` ini setting to 1 and downloaded a large file, but curl never timed out-- implying that the default value of 0 (indefinite) was still being used. I then explicitly set a CURLOPT_TIMEOUT value of one second on a curl handle, tried the to download the same file, and I noticed that the connection was definitely cut short after 1 second. – Michael Dowling Apr 12 '13 at 23:21
  • 5
    @MichaelDowling 's comment provides more information and evidence to answer this question. – Jeremy Lindblom Aug 13 '13 at 21:58
  • 3
    These developers [appear to agree](https://github.com/owncloud/core/pull/3563) - CURL doesn't honour PHP's `default_socket_timeout`. – Alex Feb 28 '14 at 11:34
  • 1
    Hey Raptor... when you have a moment... this answer is clearly incorrect (though its a good first try) and Dowlings answer is right. Could you (or some one with enough admin juice) make it the accepted answer instead? – ftrotter Apr 10 '16 at 08:06
10

None in libcurl. http://curl.haxx.se/mail/lib-2003-05/0097.html

tosin
  • 1,159
  • 7
  • 14