【发布时间】:2017-08-13 01:21:54
【问题描述】:
以下脚本:
<?php
$dnsrecs = dns_get_record('google.com'); foreach($dnsrecs as $dnsrec){ foreach($dnsrec as $label=>$val){ echo $label.':'. $val . '<br>'; } }
echo file_get_contents('https://google.com');
?>
返回一个 DNS 记录列表,但最终在 file_get_contents 上失败,尽管 phpinfo() 说:
allow_url_fopen On On
allow_url_include Off
出现以下错误:
PHP 消息:PHP 警告:file_get_contents(https://google.com):无法打开流:php_network_getaddresses:getaddrinfo 失败:从上游读取响应标头时,第 5 行的 /var/www/a.php 中没有与主机名关联的地址,客户端:152.66.34.10,服务器:xxx,请求:“GET /a.php HTTP/1.1”,上游:“fastcgi://unix:/var/run/php-fpm-www.sock:”,主机: “xxx”
服务器上的 DNS 解析工作,与运行 nginx 的用户相同:
# sudo -u www-data host google.com
google.com has address 216.58.212.142
google.com has IPv6 address 2a00:1450:400e:800::200e
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
我的 PHP 版本是最新的:
# php --version
PHP 5.5.9-1ubuntu4.21 (cli) (built: Feb 9 2017 20:54:58)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
我是通过 php5-fpm 运行的,好像和那个有关,因为sudo -u www-data php a.php 工作正常。
我的 php.ini 文件在这里:http://pastebin.com/qZePJdT5 我的 phpinfo 在这里:http://pastebin.com/cAWuu8wr
谢谢。
【问题讨论】: