Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dns Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer:
    composer require amphp/dns
    
  2. Ensure Amp is installedamphp/dns depends on amphp/amp and amphp/socket, so the event loop is automatically bootstrapped if using Amp’s standard async stack.
  3. First use case — resolve a simple A record:
    use Amp\Dns;
    
    require 'vendor/autoload.php';
    
    $address = Dns\resolve('example.com', Dns\Record::A);
    echo $address; // e.g., "93.184.216.34"
    
  4. Start with the API docs — focus on Dns\resolve(), Dns\resolveOne(), and Dns\query() methods.

Implementation Patterns

  • Batch lookups with query() for efficiency:
    $records = Dns\query('example.com', Dns\Record::MX | Dns\Record::TXT);
    
  • Custom resolvers via 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);
    
  • Integrate into async network clients (e.g., HTTP clients, TCP servers):
    Perform DNS resolution before connecting to avoid blocking on connection errors or timeouts.
  • Caching optimization:
    Built-in TTL-based caching is automatic, but you can disable it via ResolverConfig for ephemeral lookups.

Gotchas and Tips

  • Exception handling is critical — DNS failures throw Dns\Exception\DnsException or Dns\Exception\TimeoutException. Always wrap resolve() in try/catch or use Promise\timeout().
  • DNS resolution is not guaranteed synchronous — even resolve() returns a Promise. Use Amp\Promise\wait() only in CLI scripts or tests; in web apps, keep async end-to-end.
  • Caching quirks:
    • Resolver-level cache is per-resolver instance, not global. Reuse resolvers in long-lived processes.
    • Negative caching (e.g., NXDOMAIN) follows RFC standards (SOA minimum TTL), which may be longer than expected.
  • Extension points:
    • Override cache TTLs via ResolverConfig::setTtl().
    • Provide custom DNS servers or fallback logic using Dns\ServerParser.
  • Debugging tip: Use Dns\getHosts() to inspect local /etc/hosts entries for debugging precedence vs. upstream DNS.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests