1

I've installed php 5.3.14 on Ubuntu Desktop 12.04.

with: allow_url_fopen = 1

Doesn't work bellow:

<?php
echo file_get_contents('http://www.example.com');

Works bellow:

<?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);
}

Even curl_exec() works. I've also tried like this with Python, Python could fetch www contents.

I'm not using Firewall, Proxy.

But no problem with local network. (192.168.1.36 is my local server machine.)

<?php
echo file_get_contents('http://192.168.1.36);

Is any configuration or installation problems? Thanks.

peketamin
  • 151
  • 1
  • 2
  • 10

2 Answers2

1

One of the answers are:

You need to also check in PHP.ini file

extension = php_openssl.dll

If it is enable or not, if not then just enable that by removing ";" sign

DarkteK
  • 821
  • 1
  • 15
  • 26
0

This is a simular question:

PHP file_get_contents does not work on localhost

Check the answer and then it should work

Community
  • 1
  • 1
Jordi Kroon
  • 2,607
  • 3
  • 31
  • 55
  • Thank you for telling a similar question. But unfortunately `file_get_contents` **works** on local network including localhost with my environment... – peketamin Oct 10 '12 at 10:39