php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19541 mssql_connect fails under stress
Submitted: 2002-09-21 10:40 UTC Modified: 2004-03-12 13:05 UTC
Votes:8
Avg. Score:5.0 ± 0.0
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:3 (37.5%)
From: mlaukast1 at hotmail dot com Assigned:
Status: No Feedback Package: MSSQL related
PHP Version: 4.2.3 OS: Windows NT4(SP6)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mlaukast1 at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-09-21 10:40 UTC] mlaukast1 at hotmail dot com
I have found out that mssql_connect fails under stress. I'm using PHP 4.2.3/ISAPI on IIS4/NT4(SP6). MSSQL 7.0 Server is a dedicated dual processor server with NT4(SP6). I've installed MDAC 2.7 RTM on the web server and performance setting is set to foreground applications (read bug: 9852).

I've despertately searched solution to this problem, since the site I'm running is on production state already. I experienced this bug with PHP 4.2.2 at first then moved on to 4.2.3 without any change to the problem. The error occurs on a line:

$dbconn = mssql_connect($dbalias,$dbuser,$dbpw);

and application log entry for the error is:

The description for Event ID ( 2000 ) in Source ( c-client ) could not be found. It contains the following insertion string(s): , PHP Warning:  MS SQL:  Unable to connect to server:  *dbname* in *path* on line x.

I'm using TCP/IP protocol, however I've tried named pipes and multiprotocol without help. I've tried to work around this problem and I found out that usually this error occurs when several users are trying to connect to the database simultaneously. I managed to reduce the appearance of the error with the code:

function usleepWindows($usec)
{
$start = gettimeofday();

do
{
$stop = gettimeofday();
$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
+ $stop['usec'] - $start['usec'];
}
while ($timePassed < $usec);
}

$tries=11;
$totaldelay=0;
// Set db connection
$dbconn = mssql_connect($dbalias,$dbuser,$dbpw);
while(!$dbconn){
	if ($tries<=0){
		echo "Database failed to respond.";
		$fp = fopen("c:\\logs\\conn_failed.log","a");
		fputs($fp, gmdate("M d Y H:i:s") . ": db connection failed. Total delay: $totaldelay. From: $REMOTE_HOST.\r\n");
		fclose($fp);
 		exit;
	}
	$delay=mt_rand(80000, 150000);
	usleepWindows($delay);
	$conn = mssql_connect($dbalias,$dbuser,$dbpw);
	$tries--;
	$totaldelay += $delay;
}

The function usleepWindows was found from http://www.php.net/manual/en/function.usleep.php.

I haven't tried the CGI yet and wouldn't want to since it will surely suffocate the web server under load. ISAPI is far more superior and my other experiences of it are very positive.

I hope to find a solid answer to this problem as it very critical to my site.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-23 17:22 UTC] mlaukast1 at hotmail dot com
I switched to CGI and I can confirm that the error doesn't occur anymore. However, as I expected I've run into some serious performance problems under heavy load (CPU usage extremely high, script execution timeouts etc.). Therefore I'd really like to see this working under ISAPI as well. 

Does this error suggest that the mssql extension has problems with thread safety?

My opinion is that if ISAPI was stable and working well, it would be a major break-through for the PHP in Windows platforms. I honestly hope PHP group is taking Windows platforms seriously and putting effort to them.
 [2002-12-07 01:38 UTC] iliaa@php.net
Please try using this CVS snapshot:

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


 [2002-12-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2004-03-12 06:31 UTC] roger dot flink at easit dot se
I have the same problem mentioned above... :(
 [2004-03-12 13:05 UTC] fmk@php.net
The Microsoft Library (dblib) used for the mssql extension is not thread safe. To avoid problems with this extension you should use CGI or FastCGI.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC