file_get_contents不起作用,但fsockopen有效

时间:2012-10-10 10:16:18

标签: php file-get-contents fsockopen

我在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);

是否有任何配置或安装问题? 感谢。

2 个答案:

答案 0 :(得分:1)

其中一个答案是:

您还需要签入PHP.ini文件

extension = php_openssl.dll

如果是否启用,如果没有,则只需删除“;”即可启用登录

答案 1 :(得分:0)

这是一个类似的问题:

PHP file_get_contents does not work on localhost

检查答案然后它应该有效

相关问题