im hoping someone can help me quickly with a question i have.
As site i have build is occasionally returning with the error
Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in
Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in
Now at first i thought this was happening as i hadent closed the connection at the end of each page, now i get the connection like this at the beginning of a page / script
$conn = new mysqli($host, $username, $password, $database);
and at the very end call
$conn->close();
Also i close any result sets i have open.
Looking at my log files around the time i accessed the site today and saw this error, I accessed about 12 o clock and at first the page wouldnt even load, then it gave me this error. before that one person visted around 11:30 and then 10:30, not exactly heavy traffic.
The host I have gone with is very quiet and there is no way to get in contact with them, and ignoring any support emails, i thought maybe as now i hear they are not very good this could be an issue with a badly set up shared mysql server?
Any thoughts or suggestions would be amazing as i need to sort this out!
Thanks in advance!
It sounds like the MySQL server is being shared by too many accounts, as that error means that the server's max_connections
setting has been exceeded. It could be that there are several other high-traffic customers that are taking up the connections (this is a shared MySQL server, I take it?)
I'm fairly sure that PHP automatically closes resources at the end of the request (although it's always best to explicitly close your connections etc. anyway) so I wouldn't think it's your script keeping connections open.
You'll need to keep on at your hosting provider, I'm afraid, or consider moving providers. Also try to keep a log of when the errors occur and for how long, as you'll need that as evidence if they refuse to acknowledge there's a problem.
You can also refer your provider to this page: http://dev.mysql.com/doc/refman/5.1/en/too-many-connections.html.