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

dns_get_record(): DNS Query Failed

Error: dns_get_record(): DNS Query failed

1. Error: dns_get_record(): DNS Query failed. See Figure 1.

Error: dns_get_record(): DNS Query failed
Figure 1
PHP
$records = dns_get_record($host, DNS_SRV);

2. Print $host, its value is: https://object-wp.local/WP_ADMIN_USERNAME=admin

3. Open https://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. However, it is confirmed that https://object-wp.local is supported. See Figure 2.

Open https://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. However, it is confirmed that https://object-wp.local is supported.
Figure 2

4. When it starts with http://, the error still occurs: Warning: dns_get_record(): DNS Query failed. See Figure 3.

When it starts with http://, the error still occurs: Warning: dns_get_record(): DNS Query failed
Figure 3
PHP
<?php
$host = 'http://object-wp.local/WP_ADMIN_USERNAME=admin';
$records = dns_get_record($host, DNS_SRV);
?>

5. Open http://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. It is confirmed that https://object-wp.local is not supported. The web server is not listening on port 80. See Figure 4.

Open http://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. It is confirmed that https://object-wp.local is not supported. The web server is not listening on port 80.
Figure 4

6. Refer to configuring a single server for HTTP and HTTPS traffic. https://nginx.org/en/docs/http/configuring_https_servers.html .

Nginx
server {
	listen 80;
	listen 443 ssl;
}

7. Open http://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. However, it is confirmed that http://object-wp.local is now supported. See Figure 5.

Open http://object-wp.local/WP_ADMIN_USERNAME=admin in the browser, the response is 404. However, it is confirmed that http://object-wp.local is now supported.
Figure 5

8. When it starts with http://, the error still occurs: 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. When it does not start with http://, only the pure domain name remains, and the error no longer occurs. The result is an empty array.

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


10. When it does not start with http://, only the pure domain name remains, and the DNS_SRV parameter is removed. The error no longer occurs. The result is not an empty array. See Figure 6.

This confirms that there is an issue with the processing logic of the program code. At the very least, it indicates that the corresponding configuration with https:// is not supported.
Figure 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. This confirms that there is an issue with the processing logic of the program code. At the very least, it indicates that the corresponding configuration with https:// is not supported.

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

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

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

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

关于我  ·  GitHub  ·  邮件联系