#9852 [Com]: Header redirect and db connection cause "CGI misbehaved"

From: Date: Wed, 13 Oct 2004 19:09:32 +0000
Subject: #9852 [Com]: Header redirect and db connection cause "CGI misbehaved"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67545@lists.php.net to get a copy of this message
ID: 9852 Comment by: ben at sublimatic dot co dot uk Reported By: ron dot baldwin at sourceprose dot com Status: Closed Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.2.1 New Comment: I guess this isn't going to get resolved, but here are my symptoms anyway. I've got a permanent bug which has just appeared during development for no logical reason, after a very simple script change. Environment: PHP V 4.3.0 running as CGI and IUSR_... Windows 2k Advanced Server IIS5.0 MySQL (not MSSQL!) Pentium III @ 500MHz (!), ~300MB RAM, loads free Error page: CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: FATAL: erealloc(): Unable to allocate 124 bytes Situation: A script has been working perfectly for me forever. I changed one tiny thing (added a new, trivial condition to an if() statement) and ran an automated MySQL update script which added some stuff to a table and changed a couple of table column definitions, and suddenly I get this CGI error. Nothing else changed. Server configuration has been constant for months :) but suddenly I'm getting this permanent error. Whenever I hit this script the error always reappears, but only after ~20 secs of 100% processor usage by php.exe and mysqld-nt.exe (both at about 50%). I've undone my script changes: no effect. I've restarted the MySQL server: no effect. I've restarted IIS: no effect. If I drop the MySQL table which I just changed, the script runs (but obviously with a few MySQL Table Not Found-type errors). When I recreate the table, but leave it empty, the script runs. When I populate it automatically with my test data, the script crashes. However, using the normal method (i.e. through the CMS that I've built) it works fine. I can't see how this can be an IIS issue when the only thing that seems to affect the generation of this error in this case is the content of a database table. The fact that PHP and MySQL executables hog the processor for 20 seconds also seems strange to me... Hope this helps someone. Previous Comments: ------------------------------------------------------------------------ [2004-06-23 18:42:29] php at squeg dot net And, of course, I made a typo in my sample 502 page... The body tag should be: <body bgcolor="FFFFFF" onload="setTimeout( 'location.reload();', 50 );"> Note that I had double quotes around location.reload(); originally... that certainly didn't work as expected =) Change the double quotes to single quotes and all is well. ------------------------------------------------------------------------ [2004-06-23 18:36:00] php at squeg dot net A temporary fix to this issue would be to create a custom 502 error page that automatically refreshes the page (typically under c:\WINNT\Help\issHelp\common - but don't forget that you also have to set the options in Internet Services Manager... Go to Start, Programs, Administrative Tools, Internet Services Manager. Click on your host, then right click your website and select Properties. Then click the "Custom Errors" tab. Find 502 in the list and ensure that it is set to "File" and that it is pointing to your custom page). The only problem with this approach is if the user was submitting a form, they will be presented with a dialog box asking if they want to "Retry" or "Cancel", so you should mention somewhere on your custom page that they should click "Retry". Here's the custom page I hacked together out of the default 502.htm for my university: ------------ BEGIN ------------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html dir=ltr> <head> <style> a:link {font:8pt/11pt verdana; color:FF0000} a:visited {font:8pt/11pt verdana; color:#4e4e4e} </style> <META NAME="ROBOTS" CONTENT="NOINDEX"> <title>The page cannot be displayed</title> <META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252"> </head> <body bgcolor="FFFFFF" onload="setTimeout( "location.reload();", 50 );"> <h1>502: CGI Error</h1> If it asks whether to Retry or Cancel, click <b>Retry</b>. </body> </html> ------------ END ------------ The reason I used setTimeout was because if I just used location.reload(), MSIE doesn't display any text from the page, it just reloads. So I figured a really small timeout value should make it display the page first (just in case the user gets presented with that "Retry/Cancel" box). ------------------------------------------------------------------------ [2004-02-26 05:41:44] stuart at gnqs dot org I'm not sure why the PHP group haven't already done this themselves (I will ask Wez when I see him next week ;-), but anyway. I have bug# SRQ040206601696 open with Microsoft about this problem. From the analysis I've done so far (net trace of HTTP packets between IE and IIS, ISAPI filter to do what tracing I can inside IIS, tracing code added to PHP 4.3.5-rc1), the evidence comes down to this. When this error occurs, there's no evidence of php.exe being executed - for the repeatable test case that I have. What I can't *prove* (which is partly why I've opened the bug w/ Microsoft) is whether IIS actually tries to call php.exe or not. Best regards, Stu ------------------------------------------------------------------------ [2004-02-10 19:14:35] willy at vuboys dot nl I also have experienced this problem. The PHP_ISAPI seems to fix it. It seems this problem is related to a mssql connection. A solution might be to add a header() at the beginning of the script (before the mssql_connect). Is there a header of some kind which won't interfear with the other headers the application might produce? Any thoughts/comments on this? ------------------------------------------------------------------------ [2003-09-15 16:40:08] bobberz03 at hotmail dot com Was pulling my hair out with this!! Installing ISAPI module did it for me, none of the other fixes worked (did NOT try slowing anything down to get it working or messed with Background/foreground settings as this defeats the object..and some time in the future will reoccur neway!! I have created other appz using the CGI interpretor but havent tested them with the ISAPI module as yet, this is the first app I'm creating using MSSQL2000. I know its been stated above that it is IIS but I have never had this problem b4 until switching to MSSQL2000 (previously MySQL). Cheers for all the help chaps. BoB ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/9852 -- Edit this bug report at http://bugs.php.net/?id=9852&edit=1

« previous php.bugs (#67545) next »