php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20439 PHP crashed when closing connection to MSSQL
Submitted: 2002-11-15 01:31 UTC Modified: 2002-11-15 01:34 UTC
From: ulysses at mail dot fitan dot com dot tw Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 4.2.3 OS: Windows 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 + 20 = ?
Subscribe to this entry?

 
 [2002-11-15 01:31 UTC] ulysses at mail dot fitan dot com dot tw
NOTE: This situation will only happens on TRADITIONAL 
CHINESE (Big5 code) environment.

I'm using PHP4.23 (Windows binary installer version), 
TRADITINOAL CHINESE version of Windows 2000 Server with SP3 
and TRADITINOAL CHINESE version of SQL Server 2000 with 
SP2. The php_mssql.dll are extracted from PHP4.23 Windows 
binary ZIP version. Do not have other extension, 
ZendOptimizer not installed.

PHP crashed when closing connection to MSSQL under certain 
conditions. The crashing signs are: IE will not close TCP/
IP connections (even on localhost,) and php.exe will not 
stop. This problem also happens on at least three different 
servers with different Service Packs.

This crashing situation happens when SELECT datetime/
smalldatetime format column. PHP will force-convert the 
datetime format into CHINESE datetime format on TRADITIONAL 
CHINESE version of Windows 2000 Server. For example:

mssql_query('SELECT GetDate()');

and the result will be:

2002 ?Q?@?? 15 12:00?W??

You may not be able to see the Chinese words, the 6 
characters behind '2002' are 'November' in Chinese, and the 
4 characters behind '12:00' are 'AM' in Chinese.

After crash, the php.exe will stay in the task list for 10 
minutes. Sometime it may consume 99% of CPU time. And the 
SQL database will be locked, MSSQL Extension Manager may 
forbid any task related to that database, like backup, 
restore, optimize, or delete. The berserk php.exe process 
can not be terminated by Windows task manager, IIS reboot 
or shutdown MSSQL service. The only to get rid of it is to 
wait or reboot server. 

It took me lots of time to determine what's going on cause 
this crashing only happens when these two condition are 
matched:

Condition 1:
There are two or more datetime/smalldatetime columns appear 
in one query. For example, if I have a table like this:

  CREATE TABLE login_log_table (
  sn INT IDENTITY(1,1) PRIMARY KEY,
  loginname CHAR(10),
  sessionid VARCHAR(32),
  logintime SMALLDATETIME,
  logouttime SMALLDATETIME
  );

If I execute this query:

  SELECT * FROM login_log_table WHERE loginname='richard';

PHP will crash. But this query:

  SELECT
  sn, sessionid, convert(char(16),logintime,21), convert
(char(16),logintime,21) 
  FROM login_log_table WHERE loginname='richard';

that will be OK.


Condition 2:
The first process will finish the query without any 
problem, but the second process will crash.

I've one Mac G4 and 2 PCs, when I was debugging, I found 
that connections from PCs have no problem, but connection 
from Mac will crash. I don't know why until I add different 
arguments at the end of URL on a PC and crashed. For 
example:

select.php
<?
  $conn = mssql_connect("127.0.0.1","sa","xxxx");
  mssql_select_db('test_db',$conn)
  $sql = "SELECT * FROM login_log_table loginname=
'richard'";
  $res = mssql_query($sql);
  $data = mssql_fetch_row($res);
  print_r($data);
  mssql_free_result($res);
  mssql_close($conn);
?>

Suppose this code is placed on server at 192.168.1.100. 
When I first call

  http://192.168.1.100/select.php

that would be OK. Now I change the URL to:

  http://192.168.1.100/select.php?abc=def

it will crash. As you can see, variable $abc is not used in 
select.php. I tried register_globals = On/Off, same result.

I'm not Windows system engineer, but I guess there may be 
some sort of connection cache between PHP and MSSQL, though 
I did not use presistant connections in my code, and there 
may be some other sort of process cache in IIS or PHP. For 
the same connection HTTP header (URI,Agent,etc.) IIS or PHP 
may be using the cached intermediate code and process ID to 
recall the last MSSQL connection, which is also cached. Now 
the datetime format may cause a problem that prevent MSSQL 
from release the resource, as a result, the NEW process 
query for the SAME record will be blocked. That's only my 
guess.

I tried to modify the local-settings of Windows Server, and 
mssql.datetimeconvert=off in php.ini, none would work. The 
only way I can work around this problem is to avoid using 
'SELECT *' syntex in my codes.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-15 01:34 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC