/ etc/hosts不会影响PHP

Zna*_*kus 4 php linux hosts

我遇到了hosts文件和PHP的问题.运行PHP代码时root,将读取/ etc/hosts中的条目.但不是以我的用户或apache运行代码时.

root@server:/# cat /etc/hosts
127.0.0.1       mydomain.com

root@server:/# php -r "echo gethostbyname('mydomain.com');"
127.0.0.1

markus@server:/$ php -r "echo gethostbyname('mydomain.com');"
xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

Mic*_*ior 9

你确定你的/etc/hosts文件是世界可读的吗?

chmod a+r /etc/hosts