I am performing a curl request to a page. I have set both 'CURLOPT_TIMEOUT' (to 6 seconds) and 'CURLOPT_CONNECTTIMEOUT' (to 4 seconds) - and both work perfectly for most URL's.
However, when a webpage does not respond (and finally causes CURL to through a 'Could not resolve host' error (err_no 6) ) - it seems that 'CURLOPT_TIMEOUT' has no effect and curl will wait, possibly indefinately or until some 'other' timeout expires.
With the URL I am trying to access, CURL always seems to take pretty much exactly 15 seconds before it returns (which has nothing to do with the 'CURLOPT_TIMEOUT' or the 'CURLOPT_CONNECTTIMEOUT'.
Can somebody tell me how I can limit the amount of time a CURL spends attempting to resolve a host?
Well you've got 3 timeouts on your hands there.
cURL in PHP does not have a default method for setting this timeout, I would suggest resolving the hostname using another method with a timeout, and then passing the IP to cURL.
change dns resolve timeout before use cURL
putenv('RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With