简体   繁体   中英

dns_get_record(): A temporary server error occurred.

I'm querying a whole bunch of addresses, some are online and some are not. I can't seem to get around this error however, even catching the exception fails:(

 dns_get_record(): A temporary server error occurred. 


        try {
            $result = dns_get_record('_minecraft._tcp.' . $addr, DNS_SRV);
        }
        catch (Exception $e) {
            return [$addr,$port];
        }

If this error occurs, I want to continue the script, skipping the record, however currently the script just halts.

Any help appreciated!!

I can't catch this exception too. And how I understood it's a bug of php: https://bugs.php.net/bug.php?id=73149

But I found another solution. You can use @ when you call this function. This symbol kill all errors when you call this one. And it will looks like that:

$dns = @dns_get_record($domain, DNS_A);
if(!$dns){
    return false;
}

I was able to get the IP (A record) for a host using the below PHP function

gethostbynamel(string $hostname): array|false

Reference: gethostbynamel — Get a list of IPv4 addresses corresponding to a given Internet host name

try this:

     try {
         $dns = dns_get_record($domain, DNS_A);
     }
     catch (Exception $e) {
         if ($e->getMessage() !== 'dns_get_record(): A temporary server error     occurred.') {
             throw $e;
         }
         $dns = false;
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM