Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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?
CURLOPT_TIMEOUT - how long the
entire operation is taking
CURLOPT_CONNECTTIMEOUT - how long
cURL waits for the host to respond
to its request
DNS Lookup Timeout -
what you are experiencing, the DNS
query fails and takes a certain time
to do this
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.
–
–
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.