How can I change the php curl timeout when curl attempts to resolve host (curl err_no 6) How can I change the php curl timeout when curl attempts to resolve host (curl err_no 6) curl curl

How can I change the php curl timeout when curl attempts to resolve host (curl err_no 6)


Well you've got 3 timeouts on your hands there.

  1. CURLOPT_TIMEOUT - how long theentire operation is taking
  2. CURLOPT_CONNECTTIMEOUT - how longcURL waits for the host to respondto its request
  3. DNS Lookup Timeout -what you are experiencing, the DNSquery fails and takes a certain timeto 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.


change dns resolve timeout before use cURL

putenv('RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1');


In fact, CURLOPT_CONNECTTIMEOUT includes dns query time. Tested in php 5.4.9.