PHP code example of clue / mdns-react

1. Go to this page and download the library: Download clue/mdns-react library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clue / mdns-react example snippets




ory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$resolver->resolve('hostname.local')->then(function ($ip) {
    echo 'Found: ' . $ip . PHP_EOL;
}, function (Exception $e) {
    echo 'Error: ' . $e->getMessage() . PHP_EOL;
});

$factory = new Factory();

$resolver = $factory->createResolver();

$resolver->resolve($hostname)->then(
    function ($ip) {
        // IP successfully resolved
    },
    function (Exception $e) {
        // an error occurred while looking up the given hostname
    }
});



lue\React\Block;

$factory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$promise = $resolver->resolve('me.local');

try {
    $ip = Block\await($promise, $loop);
    // IP successfully resolved
} catch (Exception $e) {
    // an error occurred while performing the request
}

$promises = array(
    $resolver->resolve('first.local'),
    $resolver->resolve('second.local'),
);

$ips = Block\awaitAll($promises, $loop);