PHP Classes

File: vendor/react/dns/examples/03-cached.php

Recommend this page to a friend!
  Classes of Hillary Kollan   Chatto PHP Websocket Chat System   vendor/react/dns/examples/03-cached.php   Download  
File: vendor/react/dns/examples/03-cached.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Chatto PHP Websocket Chat System
Websocket based chat system using Ratchet library
Author: By
Last change:
Date: 3 years ago
Size: 1,156 bytes
 

Contents

Class file image Download
<?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->createCached($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->addTimer(1.0, function() use ($name, $resolver) {
   
$resolver->resolve($name)->then(function ($ip) use ($name) {
        echo
'IP for ' . $name . ': ' . $ip . PHP_EOL;
    },
'printf');
});

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

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

$loop->run();