Package list reactphp-dns / 24b821c4-1609-4c20-aa14-f3411329d7d9/main examples / 01-one.php
24b821c4-1609-4c20-aa14-f3411329d7d9/main

Tree @24b821c4-1609-4c20-aa14-f3411329d7d9/main (Download .tar.gz)

01-one.php @24b821c4-1609-4c20-aa14-f3411329d7d9/mainraw · history · blame

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

$name = isset($argv[1]) ? $argv[1] : 'www.google.com';

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

$loop->run();