2015-08-02 04:18:44 +02:00
|
|
|
# dns
|
2014-06-13 19:17:49 +02:00
|
|
|
|
2015-08-02 04:18:44 +02:00
|
|
|
[![Build Status](https://img.shields.io/travis/amphp/dns/master.svg?style=flat-square)](https://travis-ci.org/amphp/dns)
|
|
|
|
[![CoverageStatus](https://img.shields.io/coveralls/amphp/dns/master.svg?style=flat-square)](https://coveralls.io/github/amphp/dns?branch=master)
|
|
|
|
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
|
2014-07-19 15:37:48 +02:00
|
|
|
|
2017-06-22 19:22:45 +02:00
|
|
|
`amphp/dns` provides asynchronous DNS name resolution for [Amp](https://github.com/amphp/amp).
|
2014-07-19 15:37:48 +02:00
|
|
|
|
2017-06-22 19:22:45 +02:00
|
|
|
## Installation
|
2014-09-23 22:47:55 +02:00
|
|
|
|
2015-08-02 04:18:44 +02:00
|
|
|
```bash
|
2017-06-22 19:22:45 +02:00
|
|
|
composer require amphp/dns
|
2014-09-24 16:51:48 +02:00
|
|
|
```
|
|
|
|
|
2017-06-22 19:22:45 +02:00
|
|
|
## Example
|
2014-09-24 16:51:48 +02:00
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
2014-09-23 22:47:55 +02:00
|
|
|
|
2019-03-13 17:34:18 +01:00
|
|
|
require __DIR__ . '/examples/_bootstrap.php';
|
2014-09-23 22:47:55 +02:00
|
|
|
|
2017-07-06 21:22:39 +02:00
|
|
|
use Amp\Dns;
|
2017-06-22 19:22:45 +02:00
|
|
|
use Amp\Loop;
|
|
|
|
|
|
|
|
Loop::run(function () {
|
2017-07-06 21:22:39 +02:00
|
|
|
$githubIpv4 = yield Dns\resolve("github.com", Dns\Record::A);
|
2019-03-13 17:34:18 +01:00
|
|
|
pretty_print_records("github.com", $githubIpv4);
|
2014-09-23 22:47:55 +02:00
|
|
|
|
2017-07-06 21:22:39 +02:00
|
|
|
$googleIpv4 = Amp\Dns\resolve("google.com", Dns\Record::A);
|
|
|
|
$googleIpv6 = Amp\Dns\resolve("google.com", Dns\Record::AAAA);
|
2014-09-23 22:47:55 +02:00
|
|
|
|
2017-07-06 21:22:39 +02:00
|
|
|
$firstGoogleResult = yield Amp\Promise\first([$googleIpv4, $googleIpv6]);
|
2019-03-13 17:34:18 +01:00
|
|
|
pretty_print_records("google.com", $firstGoogleResult);
|
|
|
|
|
2017-07-06 21:22:39 +02:00
|
|
|
$combinedGoogleResult = yield Amp\Dns\resolve("google.com");
|
2019-03-13 17:34:18 +01:00
|
|
|
pretty_print_records("google.com", $combinedGoogleResult);
|
|
|
|
|
2017-07-06 21:22:39 +02:00
|
|
|
$googleMx = yield Amp\Dns\query("google.com", Amp\Dns\Record::MX);
|
2019-03-13 17:34:18 +01:00
|
|
|
pretty_print_records("google.com", $googleMx);
|
2014-09-23 22:47:55 +02:00
|
|
|
});
|
|
|
|
```
|