What you have observed, is probably not the source of your problem.
Have a look at the php documentation for mysql_connect and you will see that the connection is reused if the same parameters are passed which in this case, they are. Also look at the mysql_close documentation to see that it is not necessary.
For a test, I gave the code a bit of a thrashing, explicitly calling connect, as it does not get called if the $database object already exists. Note that MAX_CONNECTIONS in the MySql database used is 100 and I attempted 1000 connections.
Code: Select all
for ($i=0; $i < 1000; $i++)
{
$database =& $this->locator->get('database');
$database->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
echo $i . ' ' ;
}
I saw 1000 numbers on the screen and executing SHOW PROCESSLIST using phpmyadmin shows only
one connection. I did the same with someone else connecting from another computer to the same url and there is still only one connection.
If there are holes in what I have done here, I would appreciate any comments
