From:             web at affenkrieger dot de
Operating system: Windows 2000
PHP version:      4.3.1
PHP Bug Type:     Network related
Bug description:  fopen/fsockopen opens local file instead of doing a HTTP request

I'm runnin' a local Apache webserver 1.3.27 on my win2000 machine. PHP
4.3.1 is included as a CGI.
When i'm trying to access a non-existing file on my local Apache, PHP
tries to access it as a local file and isn't doin a HTTP request as it
should do.
Examples:

<?php
  fopen("http://localhost/404.html";, "r");
?>

PHP throws this msg into the error_log of Apache:
> PHP Fatal error:  Unknown(): Unable to open
> X:\webroot\404.html in Unknown on line 0
.. but no info to STDOUT

Doing
<?php
  fopen("http://www.gmx.de/blabla.html";, "r");
?>
Just works as expected:
> PHP Warning:  fopen(http://www.gmx.de/blabla.html)
> failed to create stream: HTTP request failed! 
> HTTP/1.1 404 Not Found

But it becomes more curious. Doing a HTTP request on my own with fsockopen
results in the same error as above!
<?php

    $fp = fsockopen ("localhost", 80, $errno, $errstr, 5);
    
    if(!$fp)
    { die($errstr);}
    
    $header_done=false;
    
    $request  = "GET /404.html HTTP/1.0\r\n";
    $request .= "User-Agent: PHP 4.3.1\r\n";
    $request .= "Host: localhost\r\n";
    $request .= "Connection: Close\r\n\r\n";
    $return = '';
    
    fputs ($fp, $request);
    
    $line = fgets ($fp, 512);
    $this->header["status"] = $line;
    
    while (!feof($fp))
    {
      if($header_done)
      { 
        $line = fread ( $fp, 1024 );
        $this->content .= $line;
      }
      else
      {
        $line = fgets ($fp, 128);
        if($line == "\r\n")
        { $header_done=true;}
        else
        {
          $data = explode(":",$line);
          $this->header[$data[0]] = trim($data[1]);
        }
      }
    }
    fclose ($fp);
?>

I am sending a HTTP GET-request to localhost to get the non-existing file,
but the answer of the Apache is "200 OK"! And then the same log entry as
with fopen():
> PHP Fatal error:  Unknown(): Unable to open
> X:\webroot\404.html in Unknown on line 0

Why does PHP wants to open a local file, even if i'm doing a HTTP request
manually ?
The same script works with an other host as expected, too.

Regards,
Nils.
-- 
Edit bug report at http://bugs.php.net/?id=22730&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22730&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22730&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22730&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22730&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22730&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22730&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22730&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22730&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22730&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22730&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22730&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22730&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22730&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22730&r=gnused

Reply via email to