2017-03-11 40 views
0

我嘗試使用Net_DNS2將域名解析爲IP地址。PHP Net_DNS2超時

public function updateStatus(){ 

    try { 

    //Works 
     $resolver = new Net_DNS2_Resolver(array(
       'nameservers' => array(37.235.1.177), 
       'use_tcp'  => false, 
       'timeout' => 20 
     )); 

     $resp = $resolver->query("swisscom.ch", 'A'); 
     echo "swisscom.ch ip: " .$resp->answer[0]->address; 


    //Triggers timout exception :(
     $resolver2 = new Net_DNS2_Resolver(array(
       'nameservers' => array(195.186.4.162), 
       'use_tcp'  => false, 
       'timeout' => 20 
     )); 

     $resp2 = $resolver2->query("swisscom.ch", 'A'); 
     echo "swisscom.ch ip: " .$resp2->answer[0]->address; 


    } catch (Exception $e) { 
     echo "<br />"; 
     print_r ($e); 
     echo "<br />"; 
    } 

}

我嘗試兩種不同的DNS服務器和37.235.1.177作品如預期,但195.186.4.162觸發此異常: https://netdns2.com/documentation/net_dns2-options/ 但它:

Net_DNS2_Exception Object ([_request:Net_DNS2_Exception:private] => [_response:Net_DNS2_Exception:private] => [message:protected] => timeout on read select() [string:Exception:private] => [code:protected] => 203 [file:protected] => /home/user/public_html/projects/Net/DNS2.php [line:protected] => 1091 [trace:Exception:private] => Array ([0] => Array ([file] => /home/user/public_html/projects/Net/DNS2.php [line] => 1393 [function] => generateError [class] => Net_DNS2 [type] => -> [args] => Array ([0] => 2 [1] => 195.186.4.162 [2] => 203)) [1] => Array ([file] => /home/user/public_html/projects/Net/DNS2.php [line] => 972 [function] => sendUDPRequest [class] => Net_DNS2 [type] => -> [args] => Array ([0] => 195.186.4.162 [1] => �Sswisscomch)) [2] => Array ([file] => /home/user/public_html/projects/Net/DNS2/Resolver.php [line] => 211 [function] => sendPacket [class] => Net_DNS2 [type] => -> [args] => Array ([0] => Net_DNS2_Packet_Request Object ([rdata] => [rdlength] => [offset] => 29 [header] => Net_DNS2_Header Object ([id] => 59475 [qr] => 0 [opcode] => 0 [aa] => 0 [tc] => 0 [rd] => 1 [ra] => 0 [z] => 0 [ad] => 0 [cd] => 0 [rcode] => 0 [qdcount] => 1 [ancount] => 0 [nscount] => 0 [arcount] => 0) [question] => Array ([0] => Net_DNS2_Question Object ([qname] => swisscom.ch [qtype] => A [qclass] => IN)) [answer] => Array () [authority] => Array () [additional] => Array () [_compressed:Net_DNS2_Packet:private] => Array ([swisscom.ch] => 12 [ch] => 21)) [1] =>)) [3] => Array ([file] => /home/user/public_html/projects/sqlInterface.php [line] => 34 [function] => query [class] => Net_DNS2_Resolver [type] => -> [args] => Array ([0] => swisscom.ch [1] => A)) [4] => Array ([file] => /home/user/public_html/projects/dnsQuery.php [line] => 7 [function] => updateStatus [class] => DBInterface [type] => -> [args] => Array ())) [previous:Exception:private] =>) 

我根據已經增加了timeoutlimit沒有幫助。任何人有一個想法出了什麼問題?

是的,兩個DNS服務器都啓動並運行。

//編輯:

echo "::query() failed: ", $e->getMessage(), "\n"; 

等於:

::query() failed: timeout on read select() 

回答

0

在幾個小時後想通了我自己。

上面的代碼沒有問題。 事實是,一些來自ISP的DNS服務器拒絕查詢來自非客戶-ips的請求。 這導致超時。