Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Default cURL timeout value

Tags:

php

curl

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

like image 456
Raptor Avatar asked Apr 25 '12 03:04

Raptor


People also ask

How does PHP handle curl timeout?

To set a timeout for a Curl command, you can use the --connect-timeout parameter to set the maximum time in seconds that you allow Curl to connect to the server, or the --max-time (or -m) parameter for the total time in seconds that you authorize the whole operation.

How do I stop my curl timing out?

Tell curl with -m / --max-time the maximum time, in seconds, that you allow the command line to spend before curl exits with a timeout error code (28). When the set time has elapsed, curl will exit no matter what is going on at that moment—including if it is transferring data. It really is the maximum time allowed.

What is curl timeout?

The –connect-timeout parameter limits the amount of time Curl will spend trying to connect to the remote host. The connection timeout value is specified in seconds. If Curl cannot establish a connection within the specified interval, the command fails.

Is PHP Curl asynchronous?

Short answer is no it isn't asynchronous. Longer answer is "Not unless you wrote the backend yourself to do so." If you're using XHR, each request is going to have a different worker thread on the backend which means no request should block any other, barring hitting process and memory limits.


1 Answers

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.

like image 85
Michael Dowling Avatar answered Sep 21 '22 03:09

Michael Dowling