1
0
mirror of https://github.com/danog/dns.git synced 2025-01-22 21:41:11 +01:00
2014-09-24 00:13:50 -04:00
2014-09-24 00:04:46 -04:00
2014-09-24 00:04:46 -04:00
2014-09-24 00:04:46 -04:00
2014-09-24 00:04:46 -04:00
2014-08-29 01:26:26 +09:00
2014-09-24 00:13:50 -04:00
2014-09-24 00:04:46 -04:00
2014-09-24 00:06:42 -04:00

dns

Asynchronous DNS resolution built on the Amp concurrency framework

Examples

Synchronous Wait

<?php

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

$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);

Parallel Async

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) {
        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();
});
Description
No description provided
Readme MIT 676 KiB
Languages
PHP 98.6%
Makefile 1.4%