PHP has these two options related to timeout: CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
.
The descriptions on the PHP site are a bit vague. What’s the difference?
To use a real world example: say you’re sending GET vars to a URL via cURL and you want to receive a XML back, would CURLOPT_CONNECTTIMEOUT
relate to the maximum amount of time it can take to connect to the server and CURLOPT_TIMEOUT
the maximum amount of time it can take to send the XML back?
Advertisement
Answer
CURLOPT_CONNECTTIMEOUT is the maximum amount of time in seconds that is allowed to make the connection to the server. It can be set to 0 to disable this limit, but this is inadvisable in a production environment.
CURLOPT_TIMEOUT is a maximum amount of time in seconds to which the execution of individual cURL extension function calls will be limited. Note that the value for this setting should include the value for CURLOPT_CONNECTTIMEOUT.
In other words, CURLOPT_CONNECTTIMEOUT is a segment of the time represented by CURLOPT_TIMEOUT, so the value of the CURLOPT_TIMEOUT should be greater than the value of the CURLOPT_CONNECTTIMEOUT.
From Difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT