Php gets too many connection errors from MySQL

I use MySQL and PHP with 2 application servers and 1 database server. With the increase in the number of users (about 1000 by now), I get the following error:

SQLSTATE[08004] [1040] Too many connections

The parameter is max_connectionsset to 1000in my.cnf, and mysql.max_persistentset to -1in php.ini.

No more than 1,500 apache processes are running, since the MaxClientsapache parameter is 750, and we have 2 application servers.

  • Should I raise max_connectionsto 1500 as indicated here ?
  • Or do I need to set mysql.max_persistentto 750 (we use PDO with constant connections for performance reasons, since the database server does not match the application servers)?
  • Or do I need to try something else?

Thanks in advance!

+3
source share
2 answers

I think your connections are not closing fast enough, and they add up until the default value is reached. I had the same problem and with wait_timeout I solved everything.

You can try installing in my.cnf

set-variable = max_connections=1000 // max connection
set-variable = max_user_connections=100 // max user connection per hour
wait_timeout = 60 // wait timeout for connection in seconds

since the completion of any existing connections after 60 seconds has passed

+3
source

I think you should check out the PHP code if you can get rid of persistent connections.

, php script , , php .

, PHP- , , .

, , mysql_connects GLOBAL, .

, , max_connections. PHP , PHP/Apache- . Max_connections .

+1

Source: https://habr.com/ru/post/1746835/


All Articles