Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving up resolution of 'SMTH', too many redirects #120

Closed
rekryt opened this issue Oct 17, 2024 · 0 comments
Closed

Giving up resolution of 'SMTH', too many redirects #120

rekryt opened this issue Oct 17, 2024 · 0 comments

Comments

@rekryt
Copy link

rekryt commented Oct 17, 2024

<?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.

throw new DnsException("Giving up resolution of '{$name}', too many redirects");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant