1
0
mirror of https://github.com/danog/dns.git synced 2024-11-30 04:29:06 +01:00
dns/README.md

71 lines
1.5 KiB
Markdown
Raw Normal View History

2014-09-23 22:47:55 +02:00
dns
===
2014-06-13 19:17:49 +02:00
2014-09-23 22:47:55 +02:00
Asynchronous DNS resolution built on the [Amp](https://github.com/amphp/amp) concurrency framework
2014-09-23 22:47:55 +02:00
## Examples
2014-09-23 22:47:55 +02:00
**Synchronous Wait**
2014-09-23 22:47:55 +02:00
```php
<?php
2014-09-23 22:47:55 +02:00
require __DIR__ . '/vendor/autoload.php';
2014-09-23 22:47:55 +02:00
$name = 'google.com';
$resolver = new Amp\Dns\Resolver;
$promise = $resolver->resolve($name);
list($address, $type) = $promise->wait();
printf("%s resolved to %s\n", $name, $address);
```
2014-09-23 22:47:55 +02:00
**Parallel Async**
```php
Amp\run(function() {
$names = [
'github.com',
'google.com',
'stackoverflow.com',
'localhost',
'192.168.0.1',
'::1',
];
$promises = [];
$resolver = new Amp\Dns\Resolver;
foreach ($names as $name) {
$promise = $resolver->resolve($name);
$promises[$name] = $promise;
}
// Combine our multiple promises into a single promise
$comboPromise = Amp\some($promises);
// Yield control until the combo promise resolves
list($errors, $successes) = (yield $comboPromise);
foreach ($names as $name) {
2014-09-24 06:06:42 +02:00
echo isset($errors[$name])
? "FAILED: {$name}\n"
: "{$name} => {$successes[$name][0]}\n";
2014-09-23 22:47:55 +02:00
}
// Stop the event loop so we don't sit around forever
Amp\stop();
});
```
2014-09-24 16:28:48 +02:00
## Tests
[![Build Status](https://travis-ci.org/amphp/dns.svg?branch=master)](https://travis-ci.org/amphp/dns)
Tests can be run from the command line using:
`php vendor/bin/phpunit -c phpunit.xml`
or to exlude tests that require a working internet connection:
`php vendor/bin/phpunit -c phpunit.xml --exclude-group internet`