【发布时间】:2012-01-15 10:36:08
【问题描述】:
我正在从 OSX 上的 MAMP 服务器本地主机 (http://172.16.65.1/) 处理我的网站。
我想从 Google 加载一些 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
对此我能做些什么? 它在我的主机提供商服务器上运行良好。
【问题讨论】:
-
您使用的是哪个版本的 MAMP?
-
Google 可能会拒绝通过 file_get_contents b/c 的请求,因为尚未定义适当的用户代理,您可能必须使用 curl; us3.php.net/curl
-
@Digital Precision 与 Curl 有同样的问题。与 Google 无关,因为任何 URL 都不会返回任何内容。我敢打赌这是我的 ISP。
-
@FFish:参考其他解决方案之一,并确保 allow_url_fopen 为 true。
-
@FFish - 您可以尝试将
file_get_contents与某个网站的数字 IP 地址一起使用,看看是否可行?
标签: php localhost echo file-get-contents