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.
dig/dns_get_record(), making it ideal for applications requiring DNS lookups without heavy dependencies. It fits well in Laravel’s ecosystem as a utility package rather than a core dependency.dig (Linux/macOS) or dns_get_record() (Windows). May need Docker/VM setup for CI or shared hosting.ttl().CouldNotFetchDns with exit codes (good for debugging).dig flags (handled via noidnout).useNameserver).dig available in all deployment environments (e.g., shared hosting, serverless)?Factory::guess() method)?Dns class as a singleton with bindings for custom handlers or configurations.
$this->app->singleton(Dns::class, function ($app) {
return (new Dns())
->setRetries(3)
->setTimeout(2);
});
Dns facade for cleaner syntax (e.g., Dns::getRecords('example.com')).use Spatie\Dns\Dns;
class CheckDnsCommand extends Command {
protected function handle() {
$records = (new Dns())->getRecords($this->argument('domain'));
$this->output->table(['Host', 'Type', 'Data'], $records);
}
}
public function handle($request, Closure $next) {
$domain = $request->input('domain');
$records = (new Dns())->getRecords($domain, 'MX');
if (empty($records)) {
abort(400, 'Invalid domain');
}
return $next($request);
}
Factory::guess() method to mock responses in tests.exec('dig ...') calls with the package for consistency.Handler interface for domain-specific logic (e.g., logging, retries).Dns for additional features (e.g., analytics).symfony/process).dig (install via apt-get install dnsutils or brew install bind).dns_get_record() (less feature-rich; may miss TTL/TTL fields).spatie/macroable (v1+) for record extensibility (optional).symfony/process (for dig execution; included via Composer).composer require spatie/dns
dig is available (which dig or dig example.com).config/services.php or a service provider.'dns' => [
'retries' => 3,
'timeout' => 5,
'default_nameserver' => '8.8.8.8',
],
Factory::guess().dig is installed in all environments (e.g., Dockerfile or CI setup).symfony/process (stable).dig not found → Install dnsutils or use dns_get_record() (Windows).setTimeout() or retry logic.noidnout flag.CouldNotFetchDns exceptions include exit codes.dig output can be logged via custom handlers.parallel:loops package.dig (e.g., symfony/process with persistent processes).dig execution (mitigate with async processing).| Failure Scenario | Impact | Mitigation |
|---|---|---|
dig unavailable |
All DNS queries fail | Fallback to dns_get_record() |
How can I help you explore Laravel packages today?