I am getting this error when trying to connect to my database:
User has already more than ‘max_user_connections’ active connections. as a result, my website has been falling over sporadically on a daily basis, and it is starting to look really bad.
My site is hosted on a shared host. I am not sure exactly how many ‘max_user_connections’ is, but before i approach them, i just want to make sure the problem is not on my side.
This is how i manage connections to the database. I define a connection in config.php. This is stored in a variable. this variable is used by all my scripts.
In the footer of all scripts i close the connection. I am using PEAR::DB (i have not found out for sure yet, but does PEAR::DB maybe use pconnect as a default? …apparently that can cause problems).
As i understand it. every page require_once’s config.php. This would make a connection…only once per page/person…and then closes it ($db->disconnect()). every page calls another page which does tracking (using pseudo-cron). this would open and close another connection. There are also 2 adverts on a page which use phpadsnew. So they would open another new connection each, so essentially there are 4 threads running per request.
So at the very worst there could be 4 connections running / page / person. My site is not huge. It usually had about 10 concurrent users at a time - 30 at a max.
So i guess there could be as many as 120 concurrent connections to the database…does that sound bad?
I thought it could be possible that i might have some-how managed to put a connection in a loop or something silly like that, but according to the phpmanual this wouldnt really cause problems:
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters.
(i am taking this to mean that each thread still opens a new connection - hence 4 connections / page)
So from that it sounds quite unlikely that the problem would be from a faulty script. Is there a better way that i should be connecting. is it possible that phpadsnew is causing problems? or is the problem with an ill configured mysql, or just too many people on a shared host?
What can i do? cause this is starting to get really bad!
PS: all these problems started when my hosts swapped a hard-drive on the server.
The connectivity has also gone down giving the following errors:
Lost connection to MySQL server during query
Can’t connect to local MySQL server through socket
Too many connections
please help!