1
0
mirror of https://github.com/danog/dns.git synced 2025-01-23 05:51:11 +01:00
dns/examples/custom-config.php
Aaron Piotrowski d26f9bb44f Remove amphp/file and amphp/uri dependencies (#80)
Replaces async loading of hosts and resolver files with blocking reads by default.

Closes #78.
2019-01-04 18:20:52 +01:00

33 lines
775 B
PHP

<?php
require __DIR__ . "/_bootstrap.php";
use Amp\Dns;
use Amp\Loop;
use Amp\Promise;
$customConfigLoader = new class implements Dns\ConfigLoader {
public function loadConfig(): Promise {
return Amp\call(function () {
$hosts = yield (new Dns\HostLoader)->loadHosts();
return new Dns\Config([
"8.8.8.8:53",
"[2001:4860:4860::8888]:53",
], $hosts, $timeout = 5000, $attempts = 3);
});
}
};
Dns\resolver(new Dns\BasicResolver(null, $customConfigLoader));
Loop::run(function () {
$hostname = "amphp.org";
try {
pretty_print_records($hostname, yield Dns\resolve($hostname));
} catch (Dns\DnsException $e) {
pretty_print_error($hostname, $e);
}
});