What CURLOPT_DNS_CACHE_TIMEOUT does

0

I wonder what this does:

curl_setopt($ch,CURLOPT_DNS_CACHE_TIMEOUT,120);

The default is 120 in lib cURL .

The following explanation, I found a little vague for me:

  

The number of seconds to keep DNS entries in memory. This option is   set to 120 (2 minutes) by default.

    
asked by anonymous 10.03.2015 / 01:21

1 answer

2

Used to set the maximum lifetime of the name resolution cache in memory. Example, suppose you ran CURL to read stackoverflow.com. It will be written in memory the IP 198.252.206.140 because it is to where the name stackoverflow.com is pointing at the moment. This is useful to avoid that, in a second connection in a short time interval, CURL has to check again what the IP is and this optimizes the performance.

A disadvantage is when you connect to an auto-traffic website where the "loadbalancer" of that website coincidentally redirects you to a second IP, which may cause some conflict with cookies. It's a rare coincidence, but it's not impossible. To ensure that the connection will actually pick up the correct IP, set to ZERO. What will happen is a small increase in CURL processing because it will force you to check DNS name resolution for all connections.

The default setting is 60 seconds, if not explicitly set. In practice, you do not have to worry too much.

More information in the documentation: link

    
10.03.2015 / 06:55