2017 © Pedro Peláez
 

library dns

Async DNS resolution for Amp.

image

amphp/dns

Async DNS resolution for Amp.

  • Wednesday, May 16, 2018
  • by amphp
  • Repository
  • 9 Watchers
  • 37 Stars
  • 114,781 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 20 Forks
  • 5 Open issues
  • 67 Versions
  • 11 % Grown

The README.md

amphp/dns

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/dns provides hostname to IP address resolution and querying specific DNS records., (*1)

Latest Release MIT License, (*2)

Installation

This package can be installed as a Composer dependency., (*3)

composer require amphp/dns

Usage

Configuration

amphp/dns automatically detects the system configuration and uses it. On Unix-like systems it reads /etc/resolv.conf and respects settings for nameservers, timeouts, and attempts. On Windows it looks up the correct entries in the Windows Registry and takes the listed nameservers. You can pass a custom ConfigLoader instance to Rfc1035StubResolver to load another configuration, such as a static config., (*4)

It respects the system's hosts file on Unix and Windows based systems, so it works just fine in environments like Docker with named containers., (*5)

The package uses a global default resolver which can be accessed and changed via Amp\Dns\resolver(). If an argument other than null is given, the resolver is used as global instance., (*6)

Usually you don't have to change the resolver. If you want to use a custom configuration for a certain request, you can create a new resolver instance and use that instead of changing the global one., (*7)

Hostname to IP Resolution

Amp\Dns\resolve provides hostname to IP address resolution. It returns an array of IPv4 and IPv6 addresses by default. The type of IP addresses returned can be restricted by passing a second argument with the respective type., (*8)

// Example without type restriction. Will return IPv4 and / or IPv6 addresses.
// What's returned depends on what's available for the given hostname.

/** @var Amp\Dns\DnsRecord[] $records */
$records = Amp\Dns\resolve("github.com");
// Example with type restriction. Will throw an exception if there are no A records.

/** @var Amp\Dns\DnsRecord[] $records */
$records = Amp\Dns\resolve("github.com", Amp\Dns\DnsRecord::A);

Custom Queries

Amp\Dns\query supports the various other DNS record types such as MX, PTR, or TXT. It automatically rewrites passed IP addresses for PTR lookups., (*9)

/** @var Amp\Dns\DnsRecord[] $records */
$records = Amp\Dns\query("google.com", Amp\Dns\DnsRecord::MX);
/** @var Amp\Dns\DnsRecord[] $records */
$records = Amp\Dns\query("8.8.8.8", Amp\Dns\DnsRecord::PTR);

Caching

The Rfc1035StubResolver caches responses by default in an Amp\Cache\LocalCache. You can set any other Amp\Cache\Cache implementation by creating a custom instance of Rfc1035StubResolver and setting that via Amp\Dns\resolver(), but it's usually unnecessary. If you have a lot of very short running scripts, you might want to consider using a local DNS resolver with a cache instead of setting a custom cache implementation, such as dnsmasq., (*10)

Reloading Configuration

The Rfc1035StubResolver (which is the default resolver shipping with that package) will cache the configuration of /etc/resolv.conf / the Windows Registry and the read host files by default. If you wish to reload them, you can set a periodic timer that requests a background reload of the configuration., (*11)

EventLoop::repeat(600, function () use ($resolver) {
    Amp\Dns\dnsResolver()->reloadConfig();
});

Note The above code relies on the resolver not being changed. reloadConfig is specific to Rfc1035StubResolver and is not part of the Resolver interface., (*12)

Example

<?php

require __DIR__ . '/examples/_bootstrap.php';

$githubIpv4 = Amp\Dns\resolve("github.com", Dns\Record::A);
pretty_print_records("github.com", $githubIpv4);

$firstGoogleResult = Amp\Future\awaitFirst([
  Amp\async(fn() => Amp\Dns\resolve("google.com", Dns\Record::A)),
  Amp\async(fn() => Amp\Dns\resolve("google.com", Dns\Record::AAAA)),
]);

pretty_print_records("google.com", $firstGoogleResult);

$combinedGoogleResult = Amp\Dns\resolve("google.com");
pretty_print_records("google.com", $combinedGoogleResult);

$googleMx = Amp\Dns\query("google.com", Amp\Dns\DnsRecord::MX);
pretty_print_records("google.com", $googleMx);

The Versions

23/10 2017

0.8.x-dev

0.8.9999999.9999999-dev https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

12/07 2017
17/06 2017
15/06 2017
17/02 2017

dev-daverandom/refactor-rewrite

dev-daverandom/refactor-rewrite https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

05/02 2017
28/01 2017

dev-res-options

dev-res-options https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

25/01 2017
05/01 2017

v0.8.12

0.8.12.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

04/11 2016

dev-fix/udp-recvfrom

dev-fix/udp-recvfrom https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

31/10 2016

dev-fix/partial-udp-timeout

dev-fix/partial-udp-timeout https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

26/05 2016

v0.8.11

0.8.11.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

26/03 2016

v0.8.10

0.8.10.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

25/03 2016

dev-inf-loop-many-requests

dev-inf-loop-many-requests https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

24/03 2016

v0.8.9

0.8.9.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

20/03 2016

v0.8.8

0.8.8.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

19/03 2016

dev-accessor

dev-accessor https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

14/03 2016

v0.8.7

0.8.7.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

29/02 2016

v0.8.6

0.8.6.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

23/12 2015

v0.8.5

0.8.5.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

08/12 2015

v0.8.4

0.8.4.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

23/09 2015

v0.8.3

0.8.3.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

18/09 2015

v0.8.2

0.8.2.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bob Weinand

client async amp dns resolve

10/09 2015

v0.8.1

0.8.1.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

08/09 2015

v0.8.0

0.8.0.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

07/09 2015

v0.7.1

0.7.1.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

02/08 2015

v0.7.0

0.7.0.0 https://github.com/amphp/dns

Async DNS resolution built on the amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

21/05 2015

v0.6.0

0.6.0.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

27/04 2015

v0.5.0

0.5.0.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

18/02 2015

v0.4.2

0.4.2.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

17/02 2015

v0.4.1

0.4.1.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

08/12 2014

v0.4.0

0.4.0.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

04/11 2014

v0.3.4

0.3.4.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

23/10 2014

v0.3.3

0.3.3.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

21/10 2014

v0.3.2

0.3.2.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

02/10 2014

v0.3.1

0.3.1.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

24/09 2014

0.3.x-dev

0.3.9999999.9999999-dev https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

24/09 2014

v0.3.0

0.3.0.0 https://github.com/amphp/dns

Asynchronous DNS resolution built on the Amp concurrency framework

  Sources   Download

MIT

The Requires

 

The Development Requires

client async amp dns resolve

05/08 2014
05/08 2014

0.2.x-dev

0.2.9999999.9999999-dev https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

01/08 2014

dev-resolverInterfaceRefactoring

dev-resolverInterfaceRefactoring https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

The Development Requires

client async dns resolve

30/07 2014

v0.2.3

0.2.3.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

17/07 2014

v0.2.2

0.2.2.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

17/07 2014

0.1.x-dev

0.1.9999999.9999999-dev https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

17/07 2014

v0.1.3

0.1.3.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

17/06 2014

v0.2.1

0.2.1.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

17/06 2014

v0.1.2

0.1.2.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

16/06 2014

v0.2.0

0.2.0.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

16/06 2014

v0.1.1

0.1.1.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve

15/06 2014

v0.1.0

0.1.0.0 https://github.com/DaveRandom/Addr

Asynchronous DNS resolver using Alert

  Sources   Download

MIT

The Requires

 

client async dns resolve