Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: Some further info on the problem: I applied the slowdown script after each query (in the simpleQuery method of PEAR's mssql driver) but I still got the occasional CGI Error (and it was awfully slow, too). I then applied the slowdown script at the start of each script, but still to no avail. What I did notice was that it did help the problem, but not eliminate it.My problem was still there when I refreshed my entire frameset (which caused 6 scripts to run mssql db commands simultaneously). Often 2 or 3 of these scripts failed with CGI errors. Previous Comments: [2002-05-28 08:30:12] [EMAIL PROTECTED] I tried the ISAPI module, but that died in *lots* of other ways - I get the impression I should stay with CGI :( I've since tried playing with the mssql parameters in php.ini (thought persistent connections may be the problem) with no success. I think I may try that slowdown script, but against all queries - it didn't work for me before the redirect - I don't always have a redirect :( Any other suggestions welcome... [2002-05-28 06:10:52] [EMAIL PROTECTED] I have the same problem, but I have some more interesting facts to add... I can reproduce it with mssql or odbc drivers, and intererstingly I can get it breaking without using a header redirect. I have an application that uses a frameset, and it appears that sometimes (2 out of 3 times) it will give me the CGI error in multiple frames, even though I've switched from header redirects to javascript redirects. The URL changes at the browser, and it's the target page that fails to load - not the page with the redirect code. I have also had it failing on another page that used the IIS custom error page functionality (i.e. replacing a 404 error with a nice custom page)...again, a "fast redirect" issue, just like the original bug reporter. I do believe it is a timing problem - for me it only fails on a fast dual-processor production server, but works fine on my slower single-processor development server. It also works fine if I shift the production server to a MySQL database. Note that I tried using the slowdown function above, but it didn't work for me - perhaps multiple simultaneous page loads from the frameset also breaks it? By the way, mine fails on version 4.2.1 (released May 2002), so obviously this little bug hasn't been caught for over a year. I read above that the ISAPI version doesn't seem to do it, so I'll look at implementing ISAPI for this job. However, that could mean that it's to do with the persistant database connection, as the ISAPI module remains loaded between page views. [2002-04-22 17:50:12] [EMAIL PROTECTED] It seems to be a timing problem (the PHP script outruns the IIS/MSSQL or something). I came up with a simple solution to this by inserting a short delay before every location header in my scripts. I successfully made the workaround by using a function from a user comment on the http://www.php.net/manual/en/function.usleep.php page The function was: -- function usleepWindows($usec) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 100 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while($timePassed < $usec); } -- Every header call should then look like this: -- usleepWindows(20); header("Location: http://www.myserver.dk/mypage.php";); exit; -- /watson [2002-04-22 16:36:05] [EMAIL PROTECTED] I tried to use both a MySQL and a MSSQL database server on the same machine. When using the MySQL database there where no problem, and when using the MSSQL database the problem was there. So the problem seems to follow the combination of: IIS and MSSQL. I have seen this error on all the PHP versions that I tried, and that is: PHP 4.0.6, PHP 4.1.1 and PHP 4.1.2. I don't know if it's in any other PHP versions besides that. [2002-03-27 13:16:00] [EMAIL PROTECTED] I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates
Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: I tried the ISAPI module, but that died in *lots* of other ways - I get the impression I should stay with CGI :( I've since tried playing with the mssql parameters in php.ini (thought persistent connections may be the problem) with no success. I think I may try that slowdown script, but against all queries - it didn't work for me before the redirect - I don't always have a redirect :( Any other suggestions welcome... Previous Comments: [2002-05-28 06:10:52] [EMAIL PROTECTED] I have the same problem, but I have some more interesting facts to add... I can reproduce it with mssql or odbc drivers, and intererstingly I can get it breaking without using a header redirect. I have an application that uses a frameset, and it appears that sometimes (2 out of 3 times) it will give me the CGI error in multiple frames, even though I've switched from header redirects to javascript redirects. The URL changes at the browser, and it's the target page that fails to load - not the page with the redirect code. I have also had it failing on another page that used the IIS custom error page functionality (i.e. replacing a 404 error with a nice custom page)...again, a "fast redirect" issue, just like the original bug reporter. I do believe it is a timing problem - for me it only fails on a fast dual-processor production server, but works fine on my slower single-processor development server. It also works fine if I shift the production server to a MySQL database. Note that I tried using the slowdown function above, but it didn't work for me - perhaps multiple simultaneous page loads from the frameset also breaks it? By the way, mine fails on version 4.2.1 (released May 2002), so obviously this little bug hasn't been caught for over a year. I read above that the ISAPI version doesn't seem to do it, so I'll look at implementing ISAPI for this job. However, that could mean that it's to do with the persistant database connection, as the ISAPI module remains loaded between page views. [2002-04-22 17:50:12] [EMAIL PROTECTED] It seems to be a timing problem (the PHP script outruns the IIS/MSSQL or something). I came up with a simple solution to this by inserting a short delay before every location header in my scripts. I successfully made the workaround by using a function from a user comment on the http://www.php.net/manual/en/function.usleep.php page The function was: -- function usleepWindows($usec) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 100 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while($timePassed < $usec); } -- Every header call should then look like this: -- usleepWindows(20); header("Location: http://www.myserver.dk/mypage.php";); exit; -- /watson [2002-04-22 16:36:05] [EMAIL PROTECTED] I tried to use both a MySQL and a MSSQL database server on the same machine. When using the MySQL database there where no problem, and when using the MSSQL database the problem was there. So the problem seems to follow the combination of: IIS and MSSQL. I have seen this error on all the PHP versions that I tried, and that is: PHP 4.0.6, PHP 4.1.1 and PHP 4.1.2. I don't know if it's in any other PHP versions besides that. [2002-03-27 13:16:00] [EMAIL PROTECTED] I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates from Windows Update. bounce.php -- BOUNCE BOUNCING BOUNCE millisecondsrequests latest cumulative [2002-01-16 13:45:10] [EMAIL PROTECTED] I have tried this with W2K server and php 4.1.1 and I am getting the same problem. Its taken a while and in fact it was only when pointed at this bug request that the answer was apparent. My problem was it wasnt constant, it was intimittent, so, I assumed my server was crud. I actually had rulled out a PHP bug coz it works fine on my portable (W2K pro) every time, but under server .. no.. Althoug
Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: I have the same problem, but I have some more interesting facts to add... I can reproduce it with mssql or odbc drivers, and intererstingly I can get it breaking without using a header redirect. I have an application that uses a frameset, and it appears that sometimes (2 out of 3 times) it will give me the CGI error in multiple frames, even though I've switched from header redirects to javascript redirects. The URL changes at the browser, and it's the target page that fails to load - not the page with the redirect code. I have also had it failing on another page that used the IIS custom error page functionality (i.e. replacing a 404 error with a nice custom page)...again, a "fast redirect" issue, just like the original bug reporter. I do believe it is a timing problem - for me it only fails on a fast dual-processor production server, but works fine on my slower single-processor development server. It also works fine if I shift the production server to a MySQL database. Note that I tried using the slowdown function above, but it didn't work for me - perhaps multiple simultaneous page loads from the frameset also breaks it? By the way, mine fails on version 4.2.1 (released May 2002), so obviously this little bug hasn't been caught for over a year. I read above that the ISAPI version doesn't seem to do it, so I'll look at implementing ISAPI for this job. However, that could mean that it's to do with the persistant database connection, as the ISAPI module remains loaded between page views. Previous Comments: [2002-04-22 17:50:12] [EMAIL PROTECTED] It seems to be a timing problem (the PHP script outruns the IIS/MSSQL or something). I came up with a simple solution to this by inserting a short delay before every location header in my scripts. I successfully made the workaround by using a function from a user comment on the http://www.php.net/manual/en/function.usleep.php page The function was: -- function usleepWindows($usec) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 100 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while($timePassed < $usec); } -- Every header call should then look like this: -- usleepWindows(20); header("Location: http://www.myserver.dk/mypage.php";); exit; -- /watson [2002-04-22 16:36:05] [EMAIL PROTECTED] I tried to use both a MySQL and a MSSQL database server on the same machine. When using the MySQL database there where no problem, and when using the MSSQL database the problem was there. So the problem seems to follow the combination of: IIS and MSSQL. I have seen this error on all the PHP versions that I tried, and that is: PHP 4.0.6, PHP 4.1.1 and PHP 4.1.2. I don't know if it's in any other PHP versions besides that. [2002-03-27 13:16:00] [EMAIL PROTECTED] I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates from Windows Update. bounce.php -- BOUNCE BOUNCING BOUNCE millisecondsrequests latest cumulative [2002-01-16 13:45:10] [EMAIL PROTECTED] I have tried this with W2K server and php 4.1.1 and I am getting the same problem. Its taken a while and in fact it was only when pointed at this bug request that the answer was apparent. My problem was it wasnt constant, it was intimittent, so, I assumed my server was crud. I actually had rulled out a PHP bug coz it works fine on my portable (W2K pro) every time, but under server .. no.. Although my server does also farm hits to the company intranet so is generally under a lot more stress than my portable. I will continue further tests to see if doing includes takes the problem away, as certainly, it seems the javascript of window.location= seems to be fine. I assume PHP is being too fast for itself? [2002-01-12 06:58:59] [EMAIL PROTECTED] Can you try this with 4.1.1? There been alot of fixes for IIS in the recent versions.
Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: It seems to be a timing problem (the PHP script outruns the IIS/MSSQL or something). I came up with a simple solution to this by inserting a short delay before every location header in my scripts. I successfully made the workaround by using a function from a user comment on the http://www.php.net/manual/en/function.usleep.php page The function was: -- function usleepWindows($usec) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 100 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while($timePassed < $usec); } -- Every header call should then look like this: -- usleepWindows(20); header("Location: http://www.myserver.dk/mypage.php";); exit; -- /watson Previous Comments: [2002-04-22 16:36:05] [EMAIL PROTECTED] I tried to use both a MySQL and a MSSQL database server on the same machine. When using the MySQL database there where no problem, and when using the MSSQL database the problem was there. So the problem seems to follow the combination of: IIS and MSSQL. I have seen this error on all the PHP versions that I tried, and that is: PHP 4.0.6, PHP 4.1.1 and PHP 4.1.2. I don't know if it's in any other PHP versions besides that. [2002-03-27 13:16:00] [EMAIL PROTECTED] I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates from Windows Update. bounce.php -- BOUNCE BOUNCING BOUNCE millisecondsrequests latest cumulative [2002-01-16 13:45:10] [EMAIL PROTECTED] I have tried this with W2K server and php 4.1.1 and I am getting the same problem. Its taken a while and in fact it was only when pointed at this bug request that the answer was apparent. My problem was it wasnt constant, it was intimittent, so, I assumed my server was crud. I actually had rulled out a PHP bug coz it works fine on my portable (W2K pro) every time, but under server .. no.. Although my server does also farm hits to the company intranet so is generally under a lot more stress than my portable. I will continue further tests to see if doing includes takes the problem away, as certainly, it seems the javascript of window.location= seems to be fine. I assume PHP is being too fast for itself? [2002-01-12 06:58:59] [EMAIL PROTECTED] Can you try this with 4.1.1? There been alot of fixes for IIS in the recent versions. [2001-03-19 22:41:31] [EMAIL PROTECTED] Under the category of "You Can Never Have Too Much Information On A Bug", here is my experience with the "CGI App Misbehaved" bug (related bug reports: #8571 and #8744). Bug report summary: A PHP script that sends a 'Location' header directive and makes a database connection causes IIS to intermittently return a 'Gateway Error 502' when the client browser asks for the page specified in the redirect. The address bar will correctly show the page that should have loaded when the error is displayed, and pressing F5 (refresh) will correctly load the page. Note that the error is (seemingly) completely random, sometimes you get it, other times the script works correctly. The error message text is: -- Begin -- CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: -- End -- This error depends on: 1) Using PHP in CGI mode (i.e. using php.exe, the ISAPI dll does not seem to produce this error, although it has it's own problems). 2) A PHP script that connects to a database (tested both mssql_connect and odbc_connect) *and* sends a 'Location:' header. If the script redirects to something other than a .php file (i.e. .html or .pdf) or does not connect to the database, the error will not occur. 3) A successful db connection. If the db connect call fails (due to bad password, etc.), the redirect always works. This error does *not* depend on: 1) A fully qualified 'Location' header. The following also fails: header('Location: http://10.0.0.3
Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: I tried to use both a MySQL and a MSSQL database server on the same machine. When using the MySQL database there where no problem, and when using the MSSQL database the problem was there. So the problem seems to follow the combination of: IIS and MSSQL. I have seen this error on all the PHP versions that I tried, and that is: PHP 4.0.6, PHP 4.1.1 and PHP 4.1.2. I don't know if it's in any other PHP versions besides that. Previous Comments: [2002-03-27 13:16:00] [EMAIL PROTECTED] I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates from Windows Update. bounce.php -- BOUNCE BOUNCING BOUNCE millisecondsrequests latest cumulative [2002-01-16 13:45:10] [EMAIL PROTECTED] I have tried this with W2K server and php 4.1.1 and I am getting the same problem. Its taken a while and in fact it was only when pointed at this bug request that the answer was apparent. My problem was it wasnt constant, it was intimittent, so, I assumed my server was crud. I actually had rulled out a PHP bug coz it works fine on my portable (W2K pro) every time, but under server .. no.. Although my server does also farm hits to the company intranet so is generally under a lot more stress than my portable. I will continue further tests to see if doing includes takes the problem away, as certainly, it seems the javascript of window.location= seems to be fine. I assume PHP is being too fast for itself? [2002-01-12 06:58:59] [EMAIL PROTECTED] Can you try this with 4.1.1? There been alot of fixes for IIS in the recent versions. [2001-03-19 22:41:31] [EMAIL PROTECTED] Under the category of "You Can Never Have Too Much Information On A Bug", here is my experience with the "CGI App Misbehaved" bug (related bug reports: #8571 and #8744). Bug report summary: A PHP script that sends a 'Location' header directive and makes a database connection causes IIS to intermittently return a 'Gateway Error 502' when the client browser asks for the page specified in the redirect. The address bar will correctly show the page that should have loaded when the error is displayed, and pressing F5 (refresh) will correctly load the page. Note that the error is (seemingly) completely random, sometimes you get it, other times the script works correctly. The error message text is: -- Begin -- CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: -- End -- This error depends on: 1) Using PHP in CGI mode (i.e. using php.exe, the ISAPI dll does not seem to produce this error, although it has it's own problems). 2) A PHP script that connects to a database (tested both mssql_connect and odbc_connect) *and* sends a 'Location:' header. If the script redirects to something other than a .php file (i.e. .html or .pdf) or does not connect to the database, the error will not occur. 3) A successful db connection. If the db connect call fails (due to bad password, etc.), the redirect always works. This error does *not* depend on: 1) A fully qualified 'Location' header. The following also fails: header('Location: http://10.0.0.30/test/done.php'); 2) The relative order of the header() and xxx_connect() calls in 'doit.php'. I wouldn't expect the order to affect the result, but I checked it anyway. Interesting note: While upgrading the server to SP1 to see if it had any affect on this bug, I continued to test while it was in the process of performing the upgrade. It was very difficult (I gave up) trying to get the error. The CPU was at 100% due to the upgrade which (obviously) caused the web server performance to suffer. Combined with the fact that it occurs randomly anyway, this suggests that it may have something to do with the timings between the request for doit.php, execution of doit.php, and the request for done.php. Hardware/Software: Web server: Win2000 Server (with and without SP1) IIS 5.0 PHP 4.0.4pl1 (CGI mode) Database server: WinNT 4.0 SP6 MS-SQL 7.0 Client: Win2000 Professional SP1 IE 5.5 SP1 ===
Bug #9852 Updated: Header redirect and db connection cause "CGI misbehaved"
ID: 9852 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: IIS related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: I can reproduce the problem with a simple "bounce" page (used for measuring roundtrip times). With two active browser windows requesting the same page, I see this error repeat (apparently at random) on one out of 10-40 thousand requests. This is with PHP 4.1.2 on Windows 2000 Professional w/ IIS 5 and all the current updates from Windows Update. bounce.php -- BOUNCE BOUNCING BOUNCE millisecondsrequests latest cumulative Previous Comments: [2002-01-16 13:45:10] [EMAIL PROTECTED] I have tried this with W2K server and php 4.1.1 and I am getting the same problem. Its taken a while and in fact it was only when pointed at this bug request that the answer was apparent. My problem was it wasnt constant, it was intimittent, so, I assumed my server was crud. I actually had rulled out a PHP bug coz it works fine on my portable (W2K pro) every time, but under server .. no.. Although my server does also farm hits to the company intranet so is generally under a lot more stress than my portable. I will continue further tests to see if doing includes takes the problem away, as certainly, it seems the javascript of window.location= seems to be fine. I assume PHP is being too fast for itself? [2002-01-12 06:58:59] [EMAIL PROTECTED] Can you try this with 4.1.1? There been alot of fixes for IIS in the recent versions. [2001-03-19 22:41:31] [EMAIL PROTECTED] Under the category of "You Can Never Have Too Much Information On A Bug", here is my experience with the "CGI App Misbehaved" bug (related bug reports: #8571 and #8744). Bug report summary: A PHP script that sends a 'Location' header directive and makes a database connection causes IIS to intermittently return a 'Gateway Error 502' when the client browser asks for the page specified in the redirect. The address bar will correctly show the page that should have loaded when the error is displayed, and pressing F5 (refresh) will correctly load the page. Note that the error is (seemingly) completely random, sometimes you get it, other times the script works correctly. The error message text is: -- Begin -- CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: -- End -- This error depends on: 1) Using PHP in CGI mode (i.e. using php.exe, the ISAPI dll does not seem to produce this error, although it has it's own problems). 2) A PHP script that connects to a database (tested both mssql_connect and odbc_connect) *and* sends a 'Location:' header. If the script redirects to something other than a .php file (i.e. .html or .pdf) or does not connect to the database, the error will not occur. 3) A successful db connection. If the db connect call fails (due to bad password, etc.), the redirect always works. This error does *not* depend on: 1) A fully qualified 'Location' header. The following also fails: header('Location: http://10.0.0.30/test/done.php'); 2) The relative order of the header() and xxx_connect() calls in 'doit.php'. I wouldn't expect the order to affect the result, but I checked it anyway. Interesting note: While upgrading the server to SP1 to see if it had any affect on this bug, I continued to test while it was in the process of performing the upgrade. It was very difficult (I gave up) trying to get the error. The CPU was at 100% due to the upgrade which (obviously) caused the web server performance to suffer. Combined with the fact that it occurs randomly anyway, this suggests that it may have something to do with the timings between the request for doit.php, execution of doit.php, and the request for done.php. Hardware/Software: Web server: Win2000 Server (with and without SP1) IIS 5.0 PHP 4.0.4pl1 (CGI mode) Database server: WinNT 4.0 SP6 MS-SQL 7.0 Client: Win2000 Professional SP1 IE 5.5 SP1 Test scripts start.php Test Do test doit.php done.php Test Test complete Reset test Here are actual HTTP headers recorded using a packet sniffer: Scenario #1 - CGI E