DNS不工作在PHP(但一般) [英] DNS not working in PHP (but does in general)

查看:250
本文介绍了DNS不工作在PHP(但一般)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本:

<?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()说:

Gives back a list of DNS records, but ends up failing on the file_get_contents, although phpinfo() says:

allow_url_fopen On  On
allow_url_include   Off

出现以下错误:


PHP消息:PHP警告:file_get_contents( https://google.com ):无法打开流:php_network_getaddresses:getaddrinfo failed:没有与/ var /客户端:152.66.34.10,server:xxx,请求:GET /a.php HTTP / 1.1,上游:fastcgi:// unix:/ var /run/php-fpm-www.sock:,host:xxx

PHP message: PHP Warning: file_get_contents(https://google.com): failed to open stream: php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /var/www/a.php on line 5" while reading response header from upstream, client: 152.66.34.10, server: xxx, request: "GET /a.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm-www.sock:", host: "xxx"

服务器上的DNS解析功能,与nginx正在运行的用户相同:

DNS resolution on the server works, with the same user as nginx is running:

# 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版本是最近的:

My PHP version is recent:

# 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 正常工作

I am running it via php5-fpm, and it seems to be related to that, because sudo -u www-data php a.php works correctly.

我的php.ini文件在这里: http://pastebin.com/qZePJdT5
我的phpinfo在这里: http://pastebin.com/cAWuu8wr

My php.ini file is here: http://pastebin.com/qZePJdT5 And my phpinfo is here: http://pastebin.com/cAWuu8wr

谢谢。

推荐答案

我们看到Goolge公共DNS服务器的确切问题。我们通过简单地重新启动PHP-FPM来修复它。这个问题一直是一些微博的主题:

We were seeing this exact issue with the Goolge public DNS servers. We fixed it by simply restarting PHP-FPM. This issue has been the topic of some twitter disucssions:

https://twitter.com/laravelphp/status/844181376224165890

但是似乎并不是DigitalOcean的具体。

However is does not seem to be DigitalOcean specific.

这篇关于DNS不工作在PHP(但一般)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆