PHP file_get_contents不适用于localhost

我正在我的网站上从localhost(http://172.16.65.1/)在OSX上运行MAMP服务器.
我想从谷歌加载一些JSON,一些简单的测试告诉我这里有一个问题..

echo file_get_contents("http://www.google.com"); // FAILS
// PHP log: [07-Dec-2011 23:09:21] PHP Warning:  file_get_contents(http://www.google.com) [<a href='function.file-get-contents'>function.file-get-contents</a>]: Failed to open stream: Host is down in /Applications/MAMP/htdocs/-tests/get-json.PHP on line 3
echo file_get_contents("http://www.yahoo.com"); // FAILS

// echo file_get_contents("http://localhost"); // WORKS
// echo file_get_contents("http://172.16.65.1/"); // WORKS - My MAMP server

我该怎么办?
它在我的主机提供商服务器上工作正常.

解决方法:

file_get_contents的文档:

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the varIoUs wrappers have, notes on their usage, and information on any predefined variables they may provide.

检查你的PHP.ini,以便allow_url_fopen设置为on.

编辑:

我没注意到你实际上可以在本地使用file_get_contents,所以现在我认为这可能与你的防火墙设置有关.

另外,如果尚未完成,请尝试在PHP.ini中设置user_agent.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...