没有不值得去解决的问题,也没有不值得去学习的技术!

dns_get_record(): DNS Query failed

报错:dns_get_record(): DNS Query failed

1、报错:dns_get_record(): DNS Query failed。如图1

报错:dns_get_record(): DNS Query failed
图1
PHP
$records = dns_get_record($host, DNS_SRV);

2、打印 $host,其值为:https://object-wp.local/WP_ADMIN_USERNAME=admin

3、在浏览器中打开:https://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。但是确定 https://object-wp.local 是支持的。如图2

在浏览器中打开:https://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。但是确定 https://object-wp.local 是支持的
图2

4、当以 http:// 开头时,仍然报错:Warning: dns_get_record(): DNS Query failed。如图3

当以 http:// 开头时,仍然报错:Warning: dns_get_record(): DNS Query failed
图3
PHP
<?php
$host = 'http://object-wp.local/WP_ADMIN_USERNAME=admin';
$records = dns_get_record($host, DNS_SRV);
?>

5、在浏览器中打开:http://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。确定 https://object-wp.local 是不受支持的。WEB 服务器未监听 80 端口。如图4

在浏览器中打开:http://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。确定 https://object-wp.local 是不受支持的。WEB 服务器未监听 80 端口
图4

6、参考可以配置一个同时处理 HTTP 和 HTTPS 请求的服务器。https://nginx.org/en/docs/http/configuring_https_servers.html 。

Nginx
server {
	listen 80;
	listen 443 ssl;
}

7、在浏览器中打开:http://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。但是确定 http://object-wp.local 已经是支持的。如图5

在浏览器中打开:http://object-wp.local/WP_ADMIN_USERNAME=admin ,响应 404。但是确定 http://object-wp.local 已经是支持的。
图5

8、当以 http:// 开头时,仍然报错:Warning: dns_get_record(): DNS Query failed。

PHP
<?php
$host = 'http://object-wp.local/WP_ADMIN_USERNAME=admin';
$records = dns_get_record($host, DNS_SRV);
?>

9、当不以 http:// 开头时,仅剩下纯粹的域名,不再报错。结果为空数组。

PHP
<?php
$host = 'object-wp.local';
$records = dns_get_record($host, DNS_SRV);
print_r($records);
?>
Plaintext
Array
(
)


10、当不以 http:// 开头时,仅剩下纯粹的域名,且去掉参数:DNS_SRV。不再报错。结果不为空数组。如图6

由此可以确认,程序代码的处理逻辑上存在一定的问题。至少说明其是不支持 https:// 的相应配置的。
图6
PHP
<?php
$host = 'object-wp.local';
$records = dns_get_record($host);
print_r($records);
?>
Plaintext

Array
(
    [0] => Array
        (
            [host] => object-wp.local
            [class] => IN
            [ttl] => 604800
            [type] => A
            [ip] => 127.0.0.1
        )

)



11、由此可以确认,程序代码的处理逻辑上存在一定的问题。至少说明其是不支持 https:// 的相应配置的。

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系