1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00
Go to file
2015-05-20 18:31:25 -04:00
examples Initial amphp refactor 2014-09-24 00:04:46 -04:00
lib Update in preparation of amp v1 2015-05-20 15:30:20 -04:00
test Update for amphp/amp v0.15.0 2014-12-08 12:07:24 -05:00
.gitignore Initial amphp refactor 2014-09-24 00:04:46 -04:00
.travis.yml Update travis 2014-09-24 10:38:34 -04:00
composer.json update composer 2015-05-20 18:31:25 -04:00
phpunit.xml Fixed typo on variable. Added ClientTest to have client specific tests. 2014-11-10 15:42:58 +00:00
README.md Add travis build status to readme 2015-05-20 15:32:25 -04:00

dns Build Status

Asynchronous DNS resolution built on the Amp concurrency framework

Examples

Synchronous Resolution Via Amp\wait()

<?php
require __DIR__ . '/vendor/autoload.php';

$resolver = new Amp\Dns\Resolver;
$name = 'google.com';
list($address, $type) = Amp\wait($resolver->resolve($name));
printf("%s resolved to %s\n", $name, $address);

Concurrent Synchronous Resolution Via wait()

<?php
require __DIR__ . '/vendor/autoload.php';

$resolver = new Amp\Dns\Resolver;
$names = [
    'github.com',
    'google.com',
    'stackoverflow.com',
];
$promises = [];
foreach ($names as $name) {
    $promises[$name] = $resolver->resolve($name);
}
$comboPromise = Amp\all($promises);
$results = Amp\wait($comboPromise);
foreach ($results as $name => $resultArray) {
    list($addr, $type) = $resultArray;
    printf("%s => %s\n", $name, $addr);
}

Event Loop Async

<?php
require __DIR__ . '/vendor/autoload.php';

Amp\run(function() {
    $resolver = new Amp\Dns\Resolver;
    $names = [
        'github.com',
        'google.com',
        'stackoverflow.com',
        'localhost',
        '192.168.0.1',
        '::1',
    ];

    $promises = [];
    foreach ($names as $name) {
        $promise = $resolver->resolve($name);
        $promises[$name] = $promise;
    }

    // Yield control until the combo promise resolves
    list($errors, $successes) = (yield 'some' => $promises);

    foreach ($names as $name) {
        echo isset($errors[$name])
            ? "FAILED: {$name}\n"
            : "{$name} => {$successes[$name][0]}\n";
    }

    // Stop the event loop so we don't sit around forever
    Amp\stop();
});

Tests

Build Status

Tests can be run from the command line using:

php vendor/bin/phpunit -c phpunit.xml

or to exclude tests that require a working internet connection:

php vendor/bin/phpunit -c phpunit.xml --exclude-group internet