php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21872 MSSQL/ODBC produce CGI Error:
Submitted: 2003-01-24 21:36 UTC Modified: 2003-02-07 23:52 UTC
Votes:3
Avg. Score:3.7 ± 1.2
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: khoker at rjobrien dot com Assigned:
Status: No Feedback Package: MSSQL related
PHP Version: 4.3.0 OS: Windows 2000
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: khoker at rjobrien dot com
New email:
PHP Version: OS:

 

 [2003-01-24 21:36 UTC] khoker at rjobrien dot com
When calling a PHP script that is using MSSQL or ODBC calls, I can reporduce this error at least one out of every ten tries, on multiple machines.  I'm at the end of my rope trying to figure it out myself.  If I can reproduce the error, I figure I am a prime candidate to help solve it.  The error states:
 
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

And that's it.  There is nothing after "are:"  

This is how I reproduce (test for) the error:  I have a PHP script that generates a webpage.  That webpage contains 4 iframes.  (The iframes are nothing more than a php page that echoes <html><body>x</body></html>.  The main page prints the code to invoke the iframes, and it also makes an MSSQL or ODBC query.  NOTE:  I can also reproduce this error when making a database call in conjuction with a header("location: ...") redirect as well, but that's a little more annoying to test than the iframes since it doesn't happen every time.
 
So, every reload on the main page is essentially 5 PHP requests (1 main + 4 iframes).  If I refresh this test page, I can get at least one of the iframes to error every 5 tries.  Which, of course, is at least one error every 25 requests.  
 
Now on to the DB.  If I comment out the DB call (be it an MSSQL or ODBC query) I cannot reproduce the error.  This is my guess...  the bug happens when PHP attempts to service a request at the exact moment something closes in the DB call.  I'm sorry I can't do any better than that for troubleshooting.  But, logically, the error is random enough that it doesn't happen EVERY time, so all I can guess is that it is a pure timing issue, which happens more frequently the more you hit the server as it is making a DB request.
 
Any other info I can offer...  I can reproduce this with IIS  on three Win2000 Servers and one Win2000 Professional box.  I am not using Named Pipes.  I've tried several versions of ntwdblib.dll and am currently using the one included with PHP 4.3.0 (12/27/2002).  I only have SQL 2000 servers to connect to, but I've reproduced this bug with the three of them that I use regularly.
 
My desktop (the Windows 2000 Professional) box is what I test with most often, and it is running Service Pack 3 and is using the current MDAC (2.7 I believe).
 
I did not use the Win32 'installer' ... rather installed via the latest .zip and my production boxes are SMP machines, so until SAPI is given the thread-safe go-ahead I have to stick with the .exe
 
I can't think of anything more off the top of my head, but I would be more than willing to give whatever feedback is requested.  Unfortunately, I thought this bug was only MSSQL related for some reason, so I've been putting off switching everything to ODBC.  I was very saddened today when I experienced the error with ODBC as well.  I've got approximately one week to solve this before I have to launch a new site with my company, and while the lauch will go either way, I don't want the executives to question my decision to use PHP instead of VBscript (as the other developers here know VB, and my argument/skills seemed strong enough to sway to the PHP side).  I'm not trying to pull any heart strings here, like I said, the site is going to launch CGI errors or not, I'd just rather have it flawless (and not field end-user calls on the issue to boot).     

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-24 22:02 UTC] khoker at rjobrien dot com
Additionally, I can offer the test script.  Here is a bare-bones example.  Testing this just now, it will error on at least one of the 6 iframes EVERY refresh.  1/6 requests is an error.  Sorry the actual DSN and SQL query does no good, but if you really wanted to try this it will save a little hassle.
 
<?
if ($_GET['dummy']) { 
  print "<html><body>x</body></html>";
  exit();
}

$sql_params = array(
  'DSN' => 'myDSN',
  'user' => 'user',
  'pass' => 'pass',
  'query' => 'SELECT DISTINCT field1 FROM table1',
);


$conn = odbc_connect($sql_params['DSN'], $sql_params['user'], $sql_params['pass']) or die("Couldn't connect to SQL Server on {$sql_params['DSN']}");
$conn_id = odbc_exec($conn, $sql_params['query']);
print odbc_num_fields($conn_id);
odbc_free_result($conn_id);
?>


<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
<IFRAME width='300px' height='300px' scrolling='no' src="test_bug.php?dummy=true"></IFRAME>
 [2003-01-25 18:21 UTC] khoker at rjobrien dot com
As of this morning, I cannot duplicate the error on my test box (Win2000 professional).  While I await the return of the CGI error, and if anyone is curious, they could ponder the following changes I made to my system.  I am not asking for this bug's state to be changed to BOGUS or CLOSED, I just want to continue providing as much information as I can.  I know there are a lot of people experiencing similar problems.
 
1)  I restarted my system, which I do every few weeks.  However, this hasn't solved anything in the past, but I wanted to include it just because it could offer a clue if the problem doesn't present itself until X hours after a reboot.  (Probably not a good clue, but a clue none-the-less).
 
2)  In restarting my system, I also applied the latest patches recommended by Microsoft's Windows Update.  These patches were from the last two weeks, and did not look to imply a fix for this issue.  Again, these were the DEFAULT patches recommended.
 
3)  I picked two additional patches from Windows Update that were not defaults.  If anyone savvy with the Win32 programming of PHP is reading, I'd be curious if you could check out these two KB articles and see if they could possibly relate.  The second one seems particularly interesting, as it relates specifically to timing.
http://support.microsoft.com/default.aspx?scid=KB;en-us;Q322842
http://support.microsoft.com/default.aspx?scid=KB;en-us;Q322913
 
I think that is it.  I understand it is extremely poor troubleshooting practice to attempt multiple 'fixes' at once, but when you've been struggling with something for months you tend to get to the point where you don't think any more changes will actually help anything.  At least I can pinpoint the two added patches which might shed light on something.
 
Again, I'll keep you posted and continue to test this issue, and would be happy to respond with any information requested.
 [2003-01-25 20:19 UTC] khoker at rjobrien dot com
Unfortunately, applying the aforementioned patches to my production server does not eliminate the problem.  That box is a Dual Xeon of some speed, as opposed to my single P4 testing box.  In order to exhibit the error there, I re-create the test script above to hold 50 iframes.  I see the error approximately one out of 400 requests in conjunction with a MSSQL/ODBC call.  
I appologize for making you read all this.
 [2003-01-25 20:36 UTC] khoker at rjobrien dot com
I have also made a test script on a dev box available to the outside world.  If a PHP developer was interested in seeing the error I will provide the link through e-mail.  Thanks.
 [2003-01-27 02:12 UTC] sniper@php.net
Please try using this CVS snapshot:

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


There were some mssql related fixes which didn't make it to 4.3.0..so please give the snapshot a go.

 [2003-02-07 23:52 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-08-08 00:00 UTC] seang at moosecat dot com dot au
I have also had a similar problem - although I am not sure of the OS  - phpinfo says that it is:
Windows NT IIS 5.0 build 2195  with an odbc / MS SQL combo
I don't get it on my XP Pro Server... - with a MySQL combo

I can rule out the odbc connection - although when I do switch the odbc back on the error happens 2-3/5 times.  When it is off I get it about 1/20 times.

It seems to be a time issue with the server - if there is no header out put within a certain amount of time (in this case less than a second) - then there is a CGI Error....
The extra time to connect to the  db seems to cause the error to happen more frequently.....  I will try a few more ideas now - like trying to flush some data through at the beginning of the script......

seang
 [2003-08-08 03:49 UTC] seang at moosecat dot com dot au
Another update....

From research it only happens on Windows OS - and not all Set ups of Windows.....  (it does not happen on my set up - just on my clients set up)

Apparently - it is not just php it happens with it is ASP too....

However there seems to be a solution..... - or at least steps to reduce the problem

http://bugs.php.net/bug.php?id=9852

From : [4 Aug 2002 10:48pm CDT] scott at datalink dot net dot au 

onwards...

in particular...
[25 Oct 2002 10:15am CDT] dmendez at artech dot com dot uy 

& 

[28 Oct 2002 4:35am CST] ewald dot murgg at fh-joanneum dot at 

& 
[3 Mar 5:23pm CST] gkasten at filnet dot fr 
&

[20 Mar 5:10pm CST] ottawasixtyseven at hotmail dot com

Come down to setting the windows system performance to Background Application - "Go to start button, control panel, system, advanced tab then performance
option." to quote one of the posts....

also if it is still happening use SAPI modules (for exapmle php4isapi.dll).  version instead of php.exe - see php.net
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 18:01:27 2024 UTC