Does Laravel's HTTP Client maintain DNS cache across PHP-FPM process lifecycles?
0 reputation · 07 Nov 2025, 13:52 UTC
0 reputation · 07 Nov 2025, 13:52 UTC
Laravel's HTTP Client leverages Guzzle to handle outgoing requests, relying on the underlying cURL extension or PHP stream wrappers for DNS resolution. While the connect_timeout option can manage the initial connection attempt, the framework does not provide a native abstraction for managing the DNS cache TTL.
In a PHP-FPM environment, where worker processes are recycled based on pm.max_requests, there is uncertainty regarding whether DNS resolution results are cached at the cURL level across different request cycles within the same worker process, or if every new request triggers a fresh lookup via the system's resolver.
What is the expected behavior for DNS caching when using the HTTP facade in a persistent PHP-FPM process? Does the underlying Guzzle handler implement any internal caching that persists between separate Laravel request lifecycles?
32775 reputation · 08 Nov 2025, 00:18 UTC
No. Laravel's HTTP Client does not maintain a DNS cache across PHP-FPM worker lifecycles. Each call through the Http facade typically creates a new Guzzle client and a new cURL easy handle. libcurl's internal DNS cache is scoped to that individual handle, not to the PHP process, and it is discarded when the handle closes. Because PHP-FPM workers can process many Laravel request cycles, it is natural to expect persistence, but neither Laravel, Guzzle, nor the default cURL handler carries DNS results from one Http::get() call to the next.
Confirmed: Guzzle's default cURL handler does not enable cURL share handles or any cross-request DNS sharing. Unless you manually reuse a cURL handle or configure a shared DNS cache, every outgoing request performs a fresh system resolver lookup. The connect_timeout option governs connection attempts, not DNS TTL, and Laravel offers no native abstraction for DNS cache management.
Likely explanation: If you observe apparent DNS persistence in a long-running PHP-FPM worker, the caching is almost certainly happening below the application layer—in the operating system's resolver. Components such as systemd-resolved, nscd, dnsmasq, or glibc's internal caching can mask the absence of application-level caching. These OS-level caches have their own TTLs and invalidation rules that are independent of PHP-FPM's pm.max_requests worker recycling.
To confirm the behavior in your environment, issue two consecutive HTTP requests to the same host from within a single PHP-FPM worker and observe resolver traffic:
strace that calls Http::get() twice against the same hostname.getaddrinfo calls or DNS packets on port 53.CURLSH share handle or custom DNS middleware is configured.One detail would change the recommendation: whether your deployment uses a local caching resolver such as systemd-resolved or dnsmasq, or relies solely on glibc's resolver. If a local caching resolver is active, OS-level caching may reduce the practical impact of repeated lookups. If not, every Http call will trigger a fresh network DNS query, and you may need to address caching at the infrastructure level rather than in application code.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.