-
-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Description
<?php
use Amp\Dns\DnsConfig;
use Amp\Dns\DnsConfigLoader;
use Amp\Dns\DnsRecord;
use Amp\Dns\HostLoader;
use Amp\Dns\Rfc1035StubDnsResolver;
use function Amp\Dns\dnsResolver as dnsResolverFactory;
require_once __DIR__ . '/vendor/autoload.php';
$dnsServers = ['1.1.1.1:53'];
$dnsResolver = dnsResolverFactory(
new Rfc1035StubDnsResolver(
null,
new class ($dnsServers) implements DnsConfigLoader {
public function __construct(private readonly array $dnsServers = []) {
}
public function loadConfig(): DnsConfig {
return new DnsConfig($this->dnsServers, (new HostLoader())->loadHosts());
}
}
)
);
$domain = 'not.existing.domain.com';
try {
$dnsResolver->resolve($domain, DnsRecord::A);
} catch (Throwable $e) {
echo $e->getMessage() . PHP_EOL;
}
$domain = 'discord.com';
try {
$dnsResolver->resolve($domain, DnsRecord::AAAA);
} catch (Throwable $e) {
echo $e->getMessage() . PHP_EOL;
}
$ php test.php
Giving up resolution of 'not.existing.domain.com', too many redirects
Giving up resolution of 'discord.com', too many redirects
When no records are retrieved from DNS, the redirect mechanism throws an DnsException.
dns/src/Rfc1035StubDnsResolver.php
Line 209 in b7515c1
throw new DnsException("Giving up resolution of '{$name}', too many redirects"); |
Metadata
Metadata
Assignees
Labels
No labels