如果我跑
php -r 'print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));'
我得到"星期二10月28日13:24:01 UTC 2014" (如预期的那样)。
但如果我有一个php文件:
<?php
print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));
它给了我:
**Warning:** file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known ...
**Warning:** file_get_contents(http://mirror.facebook.net/centos/timestamp.txt): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known ...
&#34; php -r&#34;有什么区别?和php运行文件中的代码
更新
这不是问题的答案,但它确实解决了我的问题所以为了未来的googlers:我不知道这两个解决方案中哪一个是关键,但是当我重新启动apache时它正在工作。 / p>
答案 0 :(得分:0)
您的PHP CLI使用的是其他php.ini
(或者根本没有php.ini
)。您运行与服务器使用的完全不同的PHP二进制文件也是可能的。
您可以在命令行上运行php -i
,在脚本中运行phpinfo()
以确定正在使用的php.ini
。