0

I have a large PHP/MySQL application where infrequently it will break with the error:

"already has more than max_user_connections active connections in xyz.php"

The max_user_connections limit is already set to 100 but I would prefer to see if there is an issue with my application, such as open connections or bad connections that is causing this.

I've monitored the active processes in PHPMyAdmin and can not see any that particularly hang or seem an issue.

Is there any suggestions on how to debug my code or find any possible causes to this? Would it be specifically in the xyz.php file mentioned, or is this just because my mysql connection classes are in there? The error is so temporary, only for seconds, I'm at a loss on how to hunt the cause down.

nicksource
  • 99
  • 9
  • This should help : https://stackoverflow.com/questions/4079531/mysqli-error-user-already-has-more-than-max-user-connections-active-connectio – my_workbench Aug 13 '20 at 10:54
  • @maniksidana the page you posted only suggested turning up max_user_connecitons,it is not a good choice.Big or unlimited connections will cost lots of resources leading poor performance query. – spike 王建 Aug 13 '20 at 12:49
  • @nicksource Have u ever encounted this error? How many requests received when the error raised?Have u used a connection pool or closed connection properly? – spike 王建 Aug 13 '20 at 12:51
  • Have you seen https://www.percona.com/blog/2013/11/28/mysql-error-too-many-connections/? – user3783243 Aug 13 '20 at 13:13

1 Answers1

2

Connections beyond max_user_connections configuration in mysql always leading to mysql reject new connections.For dealing with this situation

  1. You could use a connection pool to manage connections with mysql,which connection is reuseable.If you do not want to use a pool, remmbering closing connection properly!
  2. Turning up max_user_connections in my.cnf,you should measuring your host's capacity for a good configuration.Nerver set a infinite or unlimited value. Overly high number of connections will run out of host's resources,and make poor performance query because race condition.
spike 王建
  • 1,556
  • 5
  • 14
  • Thank-you. Have you got more information on how to configure a connection pool, if I am right this isn't a feature of PHP? – nicksource Aug 13 '20 at 15:36
  • 1
    @nicksource I am not famliar with php,but I found a repo on github maybe help,https://github.com/louislivi/SMProxy . According it's introduction, I think it is suitable for you – spike 王建 Aug 13 '20 at 15:47