简体   繁体   English

PHP命令行和服务器之间的区别

[英]Difference between php commandline and server

If I run 如果我跑步

php -r 'print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));'

I get "Tue Oct 28 13:24:01 UTC 2014" (as expected). 我得到“ 2014年世界标准时间10月28日星期二13:24:01”(按预期方式)。

But if I have a php file: 但是,如果我有一个php文件:

<?php
print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));

It gives me: 它给了我:

**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 ...

What is the difference between "php -r" and php running the code out of a file php -r和php从文件中运行代码有什么区别


UPDATE UPDATE

This is not the answer to the question but it did solve my problem so for the sake of future googlers: I don't know which of these two solutions was the key but it was working when I restarted apache. 这不是问题的答案,但确实解决了我的问题,因此为了将来的谷歌用户:我不知道这两种解决方案中的哪一种是关键,但是当我重新启动apache时它就起作用了。

  1. In resolv.conf set nameserver 8.8.8.8 (which had my router's address) 在resolv.conf中设置nameserver 8.8.8.8 (具有我的路由器的地址)

  2. There's an SELinux boolean httpd_can_network_connect which must be turned on: 有一个SELinux布尔值httpd_can_network_connect必须打开:

setsebool -P httpd_can_network_connect 1 setsebool -P httpd_can_network_connect 1

See this solution and this one. 请参阅解决方案和解决方案。

Your PHP CLI is using a different php.ini (or maybe no php.ini at all). 您的PHP CLI使用的是其他php.ini (或者根本没有使用php.ini )。 It's also possible you are running a completely different PHP binary than what your server is using. 也有可能您正在运行与服务器所使用的完全不同的PHP二进制文件。

You can run php -i on the command line, and phpinfo() in a script to determine which php.ini is in use. 您可以在命令行上运行php -i ,并在脚本中运行phpinfo()以确定正在使用哪个php.ini

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM