Page 1 of 1
Errors with max_user_connections
Posted: Fri Aug 21, 2015 4:33 am
by simonmlewis
Code: Select all
[20-Aug-2015 20:08:57 Europe/Dublin] PHP Warning: mysql_connect(): User <username> already has more than 'max_user_connections' active connections in /home/<username>/public_html/dbconnection.php on line 9
Hi there
We have a problem in our error logs. It may be nothing. I keep seeing these errors (with obvious changes for security here).
If this happens, does it crash out the page someone is reaching? and why would we get it? It's not a busy site. Probably less than a few 1000 hits a day at the moment.
Re: Errors with max_user_connections
Posted: Fri Aug 21, 2015 6:10 am
by Celauran
The first things I'd check are what max_user_connections is and how many users the site gets at a time and see what the discrepancy is like. If there are multiple sites running on the same host, make sure they're all running as their own users. Finally, you can go through your code checking that you aren't creating database connections when you don't need to and look at implementing some caching so the database doesn't necessarily need to be hit on every request.
Re: Errors with max_user_connections
Posted: Fri Aug 21, 2015 6:19 am
by simonmlewis
I think Google Analytics ought to tell me how many it gets at a time. Not sure of any other way.
There are multiple sites on this server, but they all use different usernames for the DBs.
Each page needs the database so the template makes the connection each time.
look at implementing some caching so the database doesn't necessarily need to be hit on every request.
How?
Re: Errors with max_user_connections
Posted: Fri Aug 21, 2015 6:23 am
by Celauran
APC, Varnish, WP caching plugins, code level caching. There are many different ways to achieve this. Google around a bit, see which you think would best fit your site.
Re: Errors with max_user_connections
Posted: Fri Aug 21, 2015 6:27 am
by simonmlewis
This would need to be for a non-templated site. ie. not Word Press.
Though there is a WP blog on the site.
Be useful to know it if it helps with the site generally.
Re: Errors with max_user_connections
Posted: Fri Aug 21, 2015 7:19 am
by Celauran
Almost certainly. Content is requested far more often than it's created, right? Say your site is for a furniture shop. You have X sofas that you sell. You might add a new model once in a while, remove one, adjust some pricing, but 99% of the time, it's the same content being served. So why hit the database every time? Query the database, build up your view, toss it in a cache. Next request you serve up the cached version and never have to hit the DB. You can adjust cache expiry to suit your particular needs, too, and it doesn't need to be the same for every page. Sometimes a week makes sense, sometimes ten minutes does.