douerqu2319 2017-03-11 12:35
浏览 95
已采纳

PHP Net_DNS2超时

I try to resolve a domain to an ip adress using 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 />";
    }

}

I try two different DNS-Servers and 37.235.1.177 works as expected but 195.186.4.162 triggers this exception:

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] => ) 

I already increased the timeoutlimit according to: https://netdns2.com/documentation/net_dns2-options/ But it does not help. Anyone have an idea what went wrong?

And yeah, both DNS-Servers are up and running.

//edit:

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

equals:

::query() failed: timeout on read select() 
  • 写回答

1条回答 默认 最新

  • donglu3243 2017-03-13 15:41
    关注

    Figured it out by myself after a few hours.

    There is nothing wrong with the code above. Fact is, some DNS-Servers from ISP's reject querying requests from non-customers-ips. And this resulted in a Timeout.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?