What makes CURLOPT_DNS_CACHE_TIMEOUT

Asked

Viewed 56 times

0

I wonder what it does:

curl_setopt($ch,CURLOPT_DNS_CACHE_TIMEOUT,120);

The standard is 120 in lib cURL.

The following explanation, I found it half vacant for me:

The number of Seconds to Keep DNS Entries in memory. This option is set to 120 (2 minutes) by default.

1 answer

2


It is used to define the maximum lifetime of the name resolution cache in memory. For example, suppose you ran CURL to read stackoverflow.com. The IP 198.252.206.140 will be stored in memory because that is where the name stackoverflow.com is currently pointing. This is useful to prevent that on a second connection in a short time interval, the CURL has to check again which is the IP and this optimizes the performance.

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

The default setting is 60 seconds if not explicitly defined. In practice, you don’t have to worry too much.

More information in the documentation: http://curl.haxx.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html

  • I expected a reply +-, but that was perfect, very good @Daniel Omine, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.