【问题标题】:dns_get_mx, dns_get_record and checkdnsrr don't work with MX (work with A though)dns_get_mx、dns_get_record 和 checkdnsrr 不能与 MX 一起使用(尽管可以与 A 一起使用)
【发布时间】:2020-02-13 17:00:51
【问题描述】:

我正在尝试验证给定域是否存在 MX 记录,但没有任何效果。

// prepare the hostname
$hostname = 'gmail.com';
$hostname = idn_to_ascii($hostname);//php.net/manual/function.checkdnsrr.php#113537
$hostname = sprintf('%s.', $hostname);//php.net/manual/function.checkdnsrr.php#119969
// perform the checks
dns_get_mx($hostname, $dns_get_mx); // a.k.a. getmxrr()
$dns_get_record = dns_get_record($hostname, DNS_MX);
$checkdnsrr = checkdnsrr($hostname, 'MX');
// output the result
var_dump(array(
    'hostname' => $hostname,
    'dns_get_mx' => $dns_get_mx,
    'dns_get_record' => $dns_get_record,
    'checkdnsrr' => $checkdnsrr,
));

这是我得到的(gmail.com.gmail.com,分别尝试):

Warning: dns_get_record(): A temporary server error occurred. in /var/www/html/example.php
array (size=4)
  'hostname' => string 'gmail.com.' (length=10)
  'dns_get_mx' => 
    array (size=0)
      empty
  'dns_get_record' => boolean false
  'checkdnsrr' => boolean false

如果我用A 替换MXdns_get_record() 返回正确的IP 地址,checkdnsrr() 返回true

日志中没有任何内容(上述警告除外),谷歌搜索也无济于事。我该如何调试?

UPD 问题出现在我本地的 VirtualBox 环境中(PHP 5.6.39);一切都在生产服务器上运行(PHP 7.3.11)

【问题讨论】:

  • 某些域可能没有 MX 记录。另外,可能是因为PHP bug
  • 您使用哪些域名服务器来获得回复?你和其他人一起尝试过吗?
  • @DanielProtopopov 我尝试了几个域,包括我们的域,我知道这些域可以正常工作。至于错误 - 他尝试了一个不存在的域,并且我的域正在工作,如果我从 MX 更改为 A,PHP 将返回值就好了
  • @PatrickMevzek 我不知道,如何找出或使用不同的名称服务器?阅读文档,上述功能不会让我指定自己的名称服务器

标签: php dns


【解决方案1】:

VirtualBox 似乎正在覆盖 /etc/resolv.conf,这会弄乱来宾计算机上的 DNS。

我现在的解决办法是:

echo "nameserver 1.1.1.1" > /etc/resolv.conf

More info

【讨论】:

    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多