file_get_contents() and HTTP_Request work at command line, but not with Apache

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I have this simple script at my server :


$page = file_get_contents(' ');

require_once 'HTTP/Request.php';
$r = new HTTP_Request(' ');
$page2 = $r->getResponseBody();

echo "<pre>\n";
print $page;
print $page2;
echo "</pre>\n";


It runs ok when run from the command line as "php index.php"
(prints the contents of twice),
but prints nothing (i.e. print only "Array ( )" for $_GET) when
called from a browser.

I'm using the stock Apache 1.3.x at OpenBSD 4.5 with the
following stock (i.e. delivered with OS) PHP packages:

php5-core-5.2.8p0   server-side HTML-embedded scripting language
php5-gd-5.2.8-no_x11 image manipulation extensions for php5
php5-pgsql-5.2.8    pgsql database access extensions for php5

It works since few years quite ok, running phpBB 3.0.x + Postgres
(upgraded few times), but now I need a new script which
would be able to fetch an external page and I can't get it working.

I'm not very proficient in PHP, please tell me,
how could I get more debugging information for my problem.

In the /var/www/conf/php.ini I have:

  allow_url_fopen = On


  display_errors = "stdout"

I also have a large "suhosin" section (as OpenBSD provides it),
haven't modified it. Also I have /var/www/etc/hosts containing       localhost

since Apache runs chrooted in /var/www under OpenBSD.
But (!!) I am also trying to run it non-chrooted (with "httpd -u")
and the script still does not work

Thank you for any help

Re: file_get_contents() and HTTP_Request work at command line, but not with Apache

A. Farber wrote:
Quoted text here. Click to load it

Since this works from the command line but not from the browser, the
obvious question is - what's different?

You're obviously running under a different environment, with different
users, paths, etc.  However, you could be using a different php
configuration or even a different version of PHP, for instance.

The first thing you should do is use phpinfo() to check your settings.
Do you have the expected settings in your web script?  How do they
differ from the the working command line version?  Especially check
which php.ini you are using - it might not be the one you expect.

Also, in addition to your display_errors directive, you should have

error_reporting=E_ALL | E_STRICT

in your php.ini file.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: file_get_contents() and HTTP_Request work at command line, but not with Apache


Quoted text here. Click to load it

thank you and I've just happened to find
the 2 reasons (after half a day searching):

1) I had a setting prohibiting outgoing web requests in my firewall:

block out quick log on $ext_if proto { tcp, udp } all user www

2) Stupid one - I haven't see the fetched page content,
because it was in XML format and the browser wasn't
displaying stuff because of < and > brackets

Thanks again.

Site Timeline