Forum Moderators: coopster

Message Too Old, No Replies

"Normal" time for CURLOPT CONNECTTIMEOUT

         

csdude55

2:41 am on Apr 4, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now that I'm switching from file_get_contents() to curl(), I have these two parameters:

CURLOPT_CONNECTTIMEOUT
CURLOPT_TIMEOUT


I more or less grasp the difference between the two, but what I'm not sure about is what a "normal" timeout would be. For testing I have them both at 60, but I understand that could realistically mean waiting for 120 seconds. So what would be a normal live setting? 5 on each?

brotherhood of LAN

10:47 am on Apr 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



CURLOPT_CONNECTTIMEOUT includes the time taken for a DNS lookup and establishing a connection to the server. A reasonable timeframe could be 3 seconds. Normally for a functioning DNS server you'd get replies within a quarter of a second, mostly depending on how far away the DNS server is to your server.

CURLOPT_TIMEOUT is for the entire operation.

A way round these timeouts is to resolve the host names before using cURL, but generally cURLs config is good enough for most cases. Also worth mentioning that more often than not DNS lookups are synchronous, mostly you're fine with setting CURLOPT_CONNECTTIMEOUT to something like 3 seconds and CURLOPT_TIMEOUT to 15 seconds or so, depending on how large your transfer will be.