|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-14 08:44 UTC] salmanarshad2000 at yahoo dot com
Description:
------------
This bug or issue has been around for quite a while and seems like nobody cares. The bug list is filled with hundreds of complains about the "The specified CGI application misbehaved ..." error each time these people have BOGUSed or CLOSEd saying things like "The version you are using is too old, please try the latest version ...", "This is not a php bug, please go to ...", "Not enough evidence ..." or "Problem with Windows, not PHP". Quite a few versions of php have been released in the meanwhile, but this issue hasn't been fixed, people who upgrade their php installation come back with the same complains. I see no good reason for this ignorance.
Problem Statement
-----------------
When browsing a php application, the IIS server randomly throws the error message:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
<BLANK>
Observations
------------
This happened only when:
- PHP.exe is used as a CGI on IIS
- The php scripts contained 2 or more frames (e.g. phpMyAdmin)
- MySQL operation was executed (update, insert, delete etc.)
- header("Location: ...") is used to redirect user after a MySQL operation to a page that also performs a MySQL operation
- The pages are viewed from local computer
- A very fast computer is used
This did not happened when:
- Apache server for windows with php support was used
- The php scripts contained 2 or more frames but all frames contained php scripts with Hello World and a random number
- Frequency of errors was much lesser when same pages were accessed from the network
- Pentium 2, 300 MHz was used (a slow computer)
History
-------
Following bugs are all related to this problem. This is just a reminder for the fact that this issue has been discussed quite a few times and it is still present. People also found these interesting things that might help to get the problem solved.
- BugID #25567 getting errors when doing a mysql_db_query() and then header("location")
- BugID #24916 header("location")
- BugID #23208 using two or more frames
- BugID #19381 no details :(
- BugID #19676 works on one (slow) system but does not work on other
- BugID #18901 header("location") after delete or update, error occurs under under load
- BugID #16313 header("location") and db operations
- BugID #23050 mysql_query() followed by header("location")
- BugID #17468 header("location")
- BugID #9852 thousands of lines describing the problem, including frames, manually slowing down the script, pages work from outside the machine nut not locally, two database connections in rapid succession etc
Things that have been said earlier
----------------------------------
"This is a problem with Microsoft OS"
No this is not, it works on exact same OS running on slower hardware or when the application is accessed across a network. And even if it is, the developers should try to find a work around instead of blaming M$ and telling it to fix it. After all, when you develop some app for an environment, you don't change the environment to suit your app (although sometimes it is easier to do so).
"This is not a php bug"
Well this could be right, since there is one other suspect, MySQL. But somebody please figure out where the problem is? Also, MySQL is now an integral part of php so problem could lie in the integration part.
My Opinion
-----------
May be php.exe is not fast enough to keep up with the pace at which IIS can throw requests at it. Or ... may be it is a problem with the MySQL connections ... attempting to create connections too quickly may be the cause. Users having same problem please feel free to contribute with their observations and suggestions.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
I can add onto / narrow down salmnarshad's info a bit: I just had this error start popping up on pages where my main frame had images added to it. I've had an image on the menu frame (which does not get updated) and it hasn't caused any errors before. In comparing against Salmnarshad's info my test cases are: -Running PHP 4.3.4 on a 2000 server as CGI under IIS -Running under 2 frames (only the main frame is being updated) -I'm making MSSQL calls not MySQL calls on both the calling page, and the next page displayed -Using a header("Location: yada yada") redirect to move between pages -The MSSQL connection is being closed just before the redirect, and reopened right after it...it is not being left open -Our server is running over 1ghz -Pages are being viewed by client machines (errors have occurred haphazardly on different clients, we have been unable to replicate the error everytime) Simplest solution seems like the easiest for me...I'm going to dump the images from the pages that are causing this problem to try and resolve it quickly on my end.I've solved me problem by adding a redirect file between my login page and start page. This way it seems that my use of header("Location: yada yada"); got some breathing room and could "catch" up and smoothly go to my start page instead of throwing a CGI error ... I use IIS 5, W2000 server with frames on start page and got the error only when i used header-function above or when i refresh my page quickly. This is not the best solution, but could be usefull in login-situation where i now put some text to tell the user that the login is processing. Redirect i used meta tag and only 1 sec delay. Hope this might solve the problem for some of you.Another clue about this weird bug is.... If you make undefined or bad system calls on a Windows box the app will throw this error. For example, in moving a PHP app from a *nix environment to a Windows2003 Server env. the following line of code WILL cause the "CGI Heart attack" to occur: system("rm /usr/local/apache/sessions/$THIS_SESSID"); That dog won't hunt on an NT machine and causes this error to occur. Remove the line (or rewrite it to use the proper NT syntax) and the error goes away.We have experienced similar probs here, except with Windows 2000 Server, CGI, and using MS SQL Server 2000. I have a theory: The DB function calls are a red herring. It's the redirection that's the problem. IIS is telling the truth. The location isn't valid. Basis: Switched to FireFox, started getting messages about the location not being found (where usually I'd get the CGI error). Looked at the code I use for redirection: header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "nextpage.php"); Found that dirname function was returning a "\" not a "/". Rewrote this as: header("Location: http://" . $_SERVER['HTTP_HOST'] . str_replace("\\","/",dirname($_SERVER['PHP_SELF'])) . "nextpage.php"); No. More. Probs. (as yet :-)) Needs testing on other setups, go ahead :-).The situation that I consistently see this bug in is: header("Location: http://site/"); The error does not occur every time. To me, this does suggest a timing issue. One piece of pertinent information is that the error is occurring on the page redirected to, and not on the page doing the redirection, as you can see from the following log entries. Steps taken to generate this were: Open web browser to default page (index.php), click on link to home.php - which detects that I am not logged in and redirects to login.php (which then fails with error 502). 2004-10-15 23:37:39 192.168.20.9 GET /index.php - 80 - 192.168.20.11 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 200 0 0 2004-10-15 23:37:41 192.168.20.9 GET /home.php - 80 - 192.168.20.11 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0 2004-10-15 23:37:41 192.168.20.9 GET /login.php - 80 - 192.168.20.11 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 502 2 0 It's a real pain - IIS doesn't give any detail in its logs about the error, there are no eventlog entries, etc., and running it through Zend Server Debugger shows no issues in the headers that I can see. This is basically the code I am using to redirect: header("Location: http://" . $_SERVER['HTTP_HOST'] . str_replace("\\", "/", dirname($_SERVER['PHP_SELF'])) . $page); exit;We've spent an extensive amount of time investigating this and have found a work-around for the PHP CGI error in the header("Location: <url>") redirect case. In our experience, this was only encountered on Windows 2003 Server and IIS 6, however it seems others have experienced similar problems elsehwere. First some observations: 1. As reported in bug #9852, changing the performance options fixes the problem on slower hardware. With faster hardware, this had no effect. Hence, it must be some kind of race condition. (to change this setting r-click on My Computer -> Advanced -> Performance -> Advanced and select Background Services) 2. If the php cgi did an odbc connection, the problem occurs. Without the odbc connection, no problem. 3. If the php cgi wastes some time in a busy loop prior to issuing the header() redirect, it works. For us, doing for($i=0; $i<1000000; $i++) did the trick. Issuing a sleep() did not work. Strange, but again, seems to indicate a race condition in IIS. 4. One of the previous posts mentioned that re-directing to the IP address instead of the domain worked. This was the primary clue to the solution. Our solution: The web browser will use the same TCP connection to send a subsequent request if it receives a Location: redirect for the same domain. In observation #4 above, it works because the re-direct is issued to an IP address which causes the browser to think the redirect is to a different system and close the existing TCP connection and make a new connection. It seems that IIS has a problem if (a) the initial CGI execution occurs very quickly and (b) a subsequent HTTP request is received over the same socket as the first request. So the work-around is to force the browser to close the TCP connection and open a new connection when a redirect occurs. This can be done by issuing a "Connection: close" header in addition to the "Location: redirect" header. The following has solved the problem for us: header("Connection: close"); header("Location: $url"); Hopefully some day Microsoft will fix this...