Errors with max_user_connections

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Errors with max_user_connections

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Errors with max_user_connections

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Errors with max_user_connections

Post 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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Errors with max_user_connections

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Errors with max_user_connections

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Errors with max_user_connections

Post 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.
Post Reply