php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13035 404 on a .php results in SERVER ERROR when using php as a cgi
Submitted: 2001-08-29 12:12 UTC Modified: 2002-11-14 01:00 UTC
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (40.0%)
From: sbeam at ne dot mediaone dot net Assigned:
Status: No Feedback Package: Other web server
PHP Version: 4.2.3 OS: Linux 2.4.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sbeam at ne dot mediaone dot net
New email:
PHP Version: OS:

 

 [2001-08-29 12:12 UTC] sbeam at ne dot mediaone dot net
If PHP is used as a CGI program via:
    Action php-script /cgi-bin/php
    AddHandler php-script .php .php3

any .php page which is not found results in 500 SERVER ERROR in the browser instead of 404 NOT FOUND. The php binary is returning nothing in its response to this situation.

To wit:

The Apache error_log reports "Premature end of script headers"

The script_log (enabled with Apache's ScriptLog directive) reports:
%% [Wed Aug 29 12:09:58 2001] GET /cgi-bin/php/nothere.php HTTP/1.0
%% 500 /usr/local/httpd/cgi-bin/php
%request
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding: gzip
Accept-Language: en
Connection: Keep-Alive
Host: localhost
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.6 i686)
%response


###
php was compiled with "'./configure' '--with-mysql=/usr' '--with-gd' '--with-imagick'                                                '--enable-discard-path' '--enable-force-cgi-redirect'"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-12 14:46 UTC] lobbin@php.net
Is still still valid with latest apache and php?
 [2002-01-17 19:32 UTC] sbeam at ne dot mediaone dot net
I dont know. I dont have 4.1.1 compiled as a CGI anywhere, won't have time to do it and test it until next week probably.
 [2002-03-07 14:26 UTC] jamie-php at hungry dot com
Yes with PHP 4.1.2 the problem occures still for me.
 [2002-03-26 18:50 UTC] morissette at dmsolutions dot ca
This problem has been annoying me for a while and is still present in 4.1.2 (CGI) at least.  I stepped through the code in a debugger and found out that when the php script doesn't exist then zend_error() is called at the lower-level, but the zend_catch in cgi_main.c catches the error and the php execution ends without any HTTP headers or anything... hence the '500 Server Error'.

I don't know enough about the way Zend works to propose a patch, but I found a nice WORKAROUND... in your php.ini, set

  log_errors=On;

This way, the error message will be sent to your Apache error_log, and the php execution will end nicely with proper HTTP headers, but an empty document, which is better than a 500 server error.
 [2002-06-13 18:04 UTC] sniper@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 [2002-10-24 08:35 UTC] morissette at dmsolutions dot ca
I would like the PHP developers to please consider reopening this bug.  I don't think it is bogus.  It still happens with  PHP 4.2.x:

The problem is simple: when using PHP as a CGI and pointing to a non-existing PHP file, instead of a 404 error we receive an empty page or a 500 - Internal Server error from the PHP CGI due to missing HTTP headers.

I think the solution is that the PHP CGI should be modified to return a 404 error header when it cannot find the .php file that it is being pointed to.
 [2002-10-28 23:27 UTC] yohgaki@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

Reopen to confirm if the problem is in 4.3.0-dev
 [2002-10-29 04:24 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-11-01 09:34 UTC] morissette at dmsolutions dot ca
OK, I downloaded and built yesterday's CVS snapshot (php4-200210311500) and the problem is still present: pointing the PHP CGI to a non-existing .php file produces no output, which results in a "missing HTTP headers" error in the Apache error_log.

I did not submit the original bug, so I'm not able to reopen this bug myself.

BTW, I tried this with an old PHP 3.0.16 CGI to see what it used to do, and PHP3 would produce the following output when pointed to a non-existing PHP file... not quite as good as a real 404 error, but better than nothing:

X-Powered-By: PHP/3.0.16
Content-type: text/html
 
<br>
<b>Fatal error</b>:  Unable to open ttt.php in <b>-</b> on line <b>0</b><br>
 [2002-11-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC