Hi!
I'm trying to run a simple php script from command line which should fetch some content from a specified website. The code looks like this:
<?php
$host = $_SERVER['argv'][1];
$path = $_SERVER['argv'][2];
$parameter = "test";
$url = "http://".$host.$path;
echo $url;
$handle = fopen($url.$parameter, "r");
$content = stream_get_contents($handle);
echo $content;
?>
Now if I run this from command line I'll get:
C:>php test.php 127.0.0.1 /path/?id=
http://127.0.0.1/path/?id=
But no content is displayed. If I change the script to:
<?php
[b]$host = "127.0.0.1";
$path = "/path/?id=";[/b]
$parameter = "test";
$url = "http://".$host.$path;
echo $url;
$handle = fopen($url.$parameter, "r");
$content = stream_get_contents($handle);
echo $content;
?>
and run it on my webserver I can see the fetched content. I've already checked my apache log, but everything looks fine as far as I can see:
// request from command line
127.0.0.1 - - [23/Nov/2007:15:39:49 +0100] "GET /path/?id=test HTTP/1.0" 200 835 - - -> /path/
So why does this work with browser, but not from command line ? Any ideas / hints ? Maybe I can't use fopen with command line?
Thanks in advance,
Reiners
edit:
allow_url_fopen = On
PHP 4.4.1-dev