spatie/dns
Fetch DNS records in PHP using dig. Query domains for A, AAAA, CNAME, MX, TXT, SRV and more, filter by type(s), and get structured record objects with handy accessors for record details.
spatie/dns package remains a lightweight, focused solution for DNS record retrieval (A, MX, TXT, etc.), ideal for validation, email routing, or domain verification. The new release does not introduce architectural changes.dns_get_record(), extendable via DnsServiceProvider).DnsRecordResolver) remain unaffected.CouldNotFetchDns exception now includes the dig exit code (PR #124). This improves debugging but requires handling the new exception structure if catching CouldNotFetchDns in custom error logic.dig exit codes in exceptions. Review existing error-handling logic to ensure compatibility with the new exception structure.
try {
Dns::get('example.com', 'MX');
} catch (CouldNotFetchDns $e) {
// $e->getExitCode() now available for debugging.
logger()->error("DNS lookup failed (exit code: {$e->getExitCode()})");
}
DnsRecordResolver.Dns facade for simple lookups.dig exit code in CouldNotFetchDns:
try {
$records = Dns::get('example.com', 'MX');
} catch (CouldNotFetchDns $e) {
// Log the exit code for debugging.
report(new DnsLookupFailed($e->getExitCode()));
}
dig exit codes for debugging:
// In a service or middleware:
Dns::get('example.com')->catch(function (CouldNotFetchDns $e) {
Sentry::captureException($e, ['exit_code' => $e->getExitCode()]);
});
dns:clear-cache and cron jobs for refreshes.CouldNotFetchDns catch blocks to handle the new getExitCode() method.dig exit codes in exceptions enhance troubleshooting:
1 = general error, 2 = server failure, etc. (refer to dig man pages)."If
CouldNotFetchDnshas exit code2, check the DNS server’s availability or network connectivity."
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| DNS Provider Unavailable | App features break. | Fallback to system DNS or queue retries. |
| Cache Stale | Outdated records. | Short TTLs + cache invalidation. |
| Rate Limiting (Cloud Providers) | API throttling. | Exponential backoff or local caching. |
| CouldNotFetchDns with Exit Code | Debugging improved. | Log exit codes for faster root-cause analysis. |
| Credential Leaks | API keys exposed. | Use Laravel’s env() or vaults. |
CouldNotFetchDns exit codes in internal runbooks.## Handling DNS Failures
If `CouldNotFetchDns` is caught:
- Exit code `1`: Invalid query or syntax.
- Exit code `2`: Server failure (check DNS server logs).
- Exit code `3`: Non-existent domain.
How can I help you explore Laravel packages today?