Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush php curl's dns cache?

Tags:

php

curl

dns

PHP Curl has a dns cache, that is enabled by default:

CURLOPT_DNS_USE_GLOBAL_CACHE

http://php.net/manual/en/function.curl-setopt.php

I can't seem to find any resources on how to clear this cache (aside from apache restart).

like image 441
Nathan Avatar asked Dec 12 '13 19:12

Nathan


People also ask

Can you flush DNS cache?

Navigate to All Programs > Accessories and select Command Prompt. In the command line interface, run ipconfig /flushdns . You should receive a confirmation message once the DNS cache is flushed.


1 Answers

It is not possible to manually clean DNS cache from PHP. But you can use CURLOPT_DNS_CACHE_TIMEOUT

Pass a long, this sets the timeout in seconds. Name resolves will be kept in memory and used for this number of seconds. Set to zero to completely disable caching, or set to -1 to make the cached entries remain forever. By default, libcurl caches this info for 60 seconds.

You can set option to 0 for next request to force curl's DNS cache to be flushed

like image 111
FallDi Avatar answered Sep 23 '22 06:09

FallDi