From:             [EMAIL PROTECTED]
Operating system: Linux and FreeBSD 4
PHP version:      4.0.4pl1
PHP Bug Type:     MySQL related
Bug description:  Bad database name leaves open connection

A Zend Help Desk customer (54) reported having an unreasonable number of connections 
to his database server in TIME_WAIT or CLOSE_WAIT state.  On closer inspection it was 
found that the database name passed to mysql_selectDB was invalid.  Correcting the 
database name appears to have hidden the problem again.

This became a major problem on his heavily loaded site because all the available 
Apache processes ended up waiting for database connections to close and made the 
server unavailable.  He is using Apache 1.13.14/PHP 4.04 on one server and MySQL 
3.23.32 on

I am able to reproduce the problem on PHP4.0.2PL1 on SuSE Linux 6.3 using MySQL 
3.22.25.  I do get an error back from the mysql_selectDB() call, but the network 
connection to the database server stays open for a minute or so, in a TIME_WAIT state. 
Connecting to the same database server, with the same username and password using the 
mysql command line interpreter, then attempting to  use  an invalid database name does 
not result in hanging connections.

The following script will demonstrate the problem:


mysql_connect( $host, $user, $password )
  or die( 'Unable to Connect - ' . mysql_error());

mysql_selectDB( 'invalid database name' )
  or die( 'Unable to Select - ' . mysql_error());

All done

Set $host, $user, $password to a MySQL database on another machine, then hit this 
program a few times with your browser.  It ends properly in the die() for Unable to 
Select, but you will find that it leaves network connections to the database server 
open in TIME_WAIT state for about a minute after the script dies.  You can verify this 

   netstat -na 

Edit Bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to