aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/dns/examples/02-concurrent.php
blob: 87e3f5ce3601cefcbc7701307ba6175bef66317e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

use React\Dns\Config\Config;
use React\Dns\Resolver\Factory;

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

$loop = React\EventLoop\Factory::create();

$config = Config::loadSystemConfigBlocking();
$server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';

$factory = new Factory();
$resolver = $factory->create($server, $loop);

$names = array_slice($argv, 1);
if (!$names) {
    $names = array('google.com', 'www.google.com', 'gmail.com');
}

foreach ($names as $name) {
    $resolver->resolve($name)->then(function ($ip) use ($name) {
        echo 'IP for ' . $name . ': ' . $ip . PHP_EOL;
    }, 'printf');
}

$loop->run();