Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

115 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dns Component

Build Status Code Climate

Async DNS resolver.

The main point of the DNS component is to provide async DNS resolution. However, it is really a toolkit for working with DNS messages, and could easily be used to create a DNS server.

Basic usage

The most basic usage is to just create a resolver through the resolver factory. All you need to give it is a nameserver, then you can start resolving names, baby!

$loop = React\EventLoop\Factory::create();
$factory = new React\Dns\Resolver\Factory();
$dns = $factory->create('8.8.8.8', $loop);

$dns->resolve('igor.io')->then(function ($ip) {
    echo "Host: $ip\n";
});

$dns->resolve('igor.io',\React\Dns\Model\Message::TYPE_MX)->then(function ($record) {
    var_dump($record);//returns array of MX Records.
});

$dns->resolve('igor.io',\React\Dns\Model\Message::TYPE_NS)->then(function ($record) {
    var_dump($record);//returns array of NS Records.
});


$loop->run();

But there's more.

Caching

You can cache results by configuring the resolver to use a CachedExecutor:

$loop = React\EventLoop\Factory::create();
$factory = new React\Dns\Resolver\Factory();
$dns = $factory->createCached('8.8.8.8', $loop);

$dns->resolve('igor.io')->then(function ($ip) {
    echo "Host: $ip\n";
});

...

$dns->resolve('igor.io')->then(function ($ip) {
    echo "Host: $ip\n";
});

$loop->run();

If the first call returns before the second, only one query will be executed. The second result will be served from cache.

Install

The recommended way to install this library is through Composer. New to Composer?

This will install the latest supported version:

$ composer require react/dns:~0.4.0

If you care a lot about BC, you may also want to look into supporting legacy versions:

$ composer require "react/dns:~0.4.0|~0.3.0"

More details and upgrade guides can be found in the CHANGELOG.

License

MIT, see LICENSE file.

References

  • RFC 1034 Domain Names - Concepts and Facilities
  • RFC 1035 Domain Names - Implementation and Specification

About

Asynchronous DNS resolver

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages