Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP cURL: CURLOPT_CONNECTTIMEOUT vs CURLOPT_TIMEOUT

Tags:

php

curl

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?

like image 215
texelate Avatar asked Jan 05 '15 08:01

texelate


People also ask

What is Curlopt_timeout?

CURLOPT_TIMEOUT. The maximum number of seconds to allow cURL functions to execute. CURLOPT_TIMEOUT_MS. The maximum number of milliseconds to allow cURL functions to execute.

What is Curlopt_connecttimeout?

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.


1 Answers

CURLOPT_CONNECTTIMEOUT is not a segment of the time represented by CURLOPT_TIMEOUT

If CURLOPT_CONNECTTIMEOUT is set to 3 seconds and CURLOPT_TIMEOUT to 4 seconds, execution may take up to 7 seconds.

I tested this by simulating slow server connecting (iptables drop).

like image 195
Miloš Avatar answered Sep 21 '22 11:09

Miloš