Difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT

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.

Example

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

Difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT Difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT Reviewed by JS Pixels on December 15, 2012 Rating: 5

5 comments:

  1. The Main Question is if CURLOPT_CONNECTTIMEOUT is set then Request is Received by Remote Server are not

    ReplyDelete
  2. if i set CURLOPT_TIMEOUT = 1, so request run in background??

    ReplyDelete
  3. I found this page as I'm investigating an issue in our production environment.

    We have a remote HTTP connection where we set:

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);

    However we have networking monitoring that measured a small amount of 28 second response times for this connection.

    If the connection timeout is a subset of the total timeout, I would expect to never see any response time > 20. In fact for a while it was averaging 28 seconds during a period of degradation for the remote service.

    I am suspicious that if a connection took 9 seconds, and the response an addition 19, that could add up to 28 total seconds.

    Is there more evidence that the connection timeout duration is included in the total, and that both parts are not summed together?

    Thanks
    -Sean

    ReplyDelete
  4. I did some testing to try to confirm this behavior, and thought I'd share. The conclusion that I've drawn is that CONNECTTIMEOUT cannot be greater than TIMEOUT - but that TIMEOUT is not necessarily "inclusive" of CONNECTTIMEOUT, so it is possible to have a total connection time of CONNECTTIMEOUT+TIMEOUT.

    I forced my DNS lookups to take 5 seconds timeout, so that I can simulate a slow connection. Knowing this, I set the CONNECTTIMEOUT to 60 seconds, then:

    If I set the TIMEOUT to 5 seconds, I get an "Error in cURL request: name lookup timed out" error after 5 seconds (meaning TIMEOUT has effectively overridden CONNECTTIMEOUT).

    However, if I set TIMEOUT to 6 seconds, I then get a "Error in cURL request: Operation timed out after 6000 milliseconds with 0 bytes received" error after *11* seconds (5 seconds of DNS + 6 seconds of connection).

    This was tested on PHP 5.5.32 with libcurl 7.19.7 installed.

    ReplyDelete
  5. SimpleXMLElement Object
    (
    [Error] => Internal Error Time Out. Please try again later
    [AvailRequest] => SimpleXMLElement Object
    (
    [Trip] => ONE
    [Origin] => DEL
    [Destination] => DXB
    [DepartDate] => 2016-08-29
    [ReturnDate] => 2016-08-30
    [AdultPax] => 1
    [ChildPax] => 0
    [InfantPax] => 0
    [Currency] => INR
    [PreferredClass] => E
    [Eticket] => true
    [Clientid] => 77743673
    [Clienttype] => ArzooINTLWS1.0
    [PreferredAirline] => SimpleXMLElement Object




    Please Help In this code

    ReplyDelete

Altaf Web. Powered by Blogger.