tags:

views:

45

answers:

1

Hello all, 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!

+1  A: 

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.

Andy Shellam
thanks for the reply...so you dont think its my fault then! :)
Dori
It doesn't appear so. If you get in contact with your provider, tell them to examine the results of running "SHOW PROCESSLIST" against the MySQL server - it will show which connections are coming from which servers.
Andy Shellam
Also just check your script is not creating persistent connections - make sure your hostname does NOT start with `p:` (unless you want persistent connections but then you really have to check that the connections are being closed/disposed of correctly.)
Andy Shellam
host name is just 'localhost', is that what you mean?host has now got in touch saying they are having load issues...stupid shared server.I wouldve thought even with a shared server you could specify each database could only consume x amount of connections and not let one site suck them all up!
Dori
Even more worrying, is why are they running both web and database on the same server, especially as it's shared hosting?
Andy Shellam