【发布时间】:2012-09-30 18:51:27
【问题描述】:
我已经在 Ubuntu Desktop 12.04 上安装了 php 5.3.14。
与: allow_url_fopen = 1
下面不起作用:
<?php
echo file_get_contents('http://www.example.com');
工作如下:
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
甚至 curl_exec() 也有效。 我也用 Python 试过这样,Python 可以获取 www 内容。
我没有使用防火墙、代理。
但是本地网络没有问题。 (192.168.1.36 是我的本地服务器机器。)
<?php
echo file_get_contents('http://192.168.1.36);
是否有任何配置或安装问题? 谢谢。
【问题讨论】:
-
file_get_contents不起作用时会出现什么错误? -
打开完整的错误报告后,您不会收到任何错误吗? - 难以置信。
-
@Leigh 和
error_reporting(E_ALL); -
@MrCode 错误是
PHP Warning: file_get_contents(http://www.example.com/): failed to open stream: HTTP request failed! in /path/to/test.php on line 14
标签: php file-get-contents fsockopen