- How do I install spatie/dns in a Laravel application?
- Install it with composer require spatie/dns. There is no Laravel service provider, facade, config file, or auto-discovery because the package is framework-agnostic. You can use the Spatie\Dns\Dns class directly or bind it in your own service provider.
- Does spatie/dns support Laravel 10, Laravel 11, and Laravel 12?
- Spatie/DNS is a framework-agnostic PHP 8.0+ library, so it does not declare Laravel version constraints. It will work with any Laravel version that runs on PHP 8.0 or newer. Laravel integration is entirely up to your application code.
- What DNS record types can spatie/dns retrieve?
- It can retrieve A, AAAA, CNAME, NS, PTR, SOA, MX, SRV, TXT, DNSKEY, CAA, and NAPTR records. You can request all records for a domain or filter by one or more types. Records are returned as typed objects with accessors such as host(), ttl(), type(), and A::ip().
- How do I get only MX or TXT records with spatie/dns?
- Pass the record type as the second argument to getRecords(), for example getRecords('example.com', 'MX') or getRecords('example.com', 'TXT'). You can also pass an array like ['A', 'CNAME'] or use PHP DNS constants such as DNS_MX. The method returns only the matching record objects.
- Do I need dig installed to use spatie/dns?
- Dig is strongly recommended and is the primary handler. If dig is missing, the package falls back to PHP's native dns_get_record(), but behavior is not identical: retry and timeout controls are unavailable and parsing or metadata fidelity may differ. In Docker, Vapor, Lambda, or distroless images, install dnsutils or bind-utils explicitly.
- How do I set a custom nameserver, timeout, or retry count in spatie/dns?
- Use the fluent methods on the Dns class: useNameserver(), setTimeout(), and setRetries(). For example, call useNameserver('1.1.1.1') before getRecords(). These options apply to the dig handler and are not behaviorally identical under the native dns_get_record() fallback.
- Is spatie/dns safe to use on the Laravel request hot path?
- No, it is a poor fit for request-path DNS lookups. Each getRecords() call shells out through symfony/process, forking a process and typically taking tens of milliseconds with no connection reuse or batching. Move bulk domain verification or enrichment work to queued jobs or scheduled tasks.
- How do I test Laravel code that uses spatie/dns?
- Wrap the package behind your own interface or adapter and fake that in tests. Spatie/DNS does not ship a Laravel fake, but its small API makes a one-class wrapper practical. You can also use the handler abstraction with useHandlers() to inject custom behavior during tests.
- Can spatie/dns handle long TXT records such as SPF and DMARC?
- It returns TXT records as record objects, but long TXT values over 255 characters, multi-string SPF or DMARC records, IDN domains, and NAPTR or SRV records are the highest-risk parsing surfaces. Historical releases have fixed TXT, PTR, and NS parsing edge cases. Validate real-world records for your domains before relying on parsed values.
- What are alternatives to spatie/dns for DNS lookups in Laravel?
- You can use PHP's native dns_get_record() directly, but you lose retry and timeout controls and typed record objects. If you need DNS-over-HTTPS or API-backed lookups, implement a custom handler through the package's Handler abstraction and register it with useHandlers(). Because the library is small, replacing it with a focused wrapper is also low-effort.