amphp/dns
Async DNS resolver for PHP built on Amp. Provides non-blocking hostname lookups, record queries, caching and timeouts with an event loop, ideal for high-concurrency applications and CLI tools needing fast, reliable DNS without blocking I/O.
composer require amphp/dns
amphp/dns depends on amphp/amp and amphp/socket, so the event loop is automatically bootstrapped if using Amp’s standard async stack.use Amp\Dns;
require 'vendor/autoload.php';
$address = Dns\resolve('example.com', Dns\Record::A);
echo $address; // e.g., "93.184.216.34"
Dns\resolve(), Dns\resolveOne(), and Dns\query() methods.query() for efficiency:
$records = Dns\query('example.com', Dns\Record::MX | Dns\Record::TXT);
ResolverFactory or BootstrapResolver for environments with custom DNS (e.g., Docker, internal networks):
$resolver = (new Dns\BootstrapResolverFactory())->create(['8.8.8.8', '1.1.1.1']);
$ip = Dns\resolve('example.com', Dns\Record::A, $resolver);
ResolverConfig for ephemeral lookups.Dns\Exception\DnsException or Dns\Exception\TimeoutException. Always wrap resolve() in try/catch or use Promise\timeout().resolve() returns a Promise. Use Amp\Promise\wait() only in CLI scripts or tests; in web apps, keep async end-to-end.SOA minimum TTL), which may be longer than expected.ResolverConfig::setTtl().Dns\ServerParser.Dns\getHosts() to inspect local /etc/hosts entries for debugging precedence vs. upstream DNS.How can I help you explore Laravel packages today?