Handling Large Number of MySQLi Connections in PHP

MySQLmysqliPHP

I run a php site with mysqli. I got 3551496 Connections, but there were only 30 processes

  1. How can It be
  2. What should I do about it?
  3. The server is up for 6 month, The problem is that I keep getting too many connections error

enter image description here

enter image description here

Best Answer

  • 1) How can it be?

If you check the documentation for server status variables, this number (3551496) is:

The number of connection attempts (successful or not) to the MySQL server.

i.e. the number of connections (plus attempts to connect) since the server was booted!

The number of active connections can be verified by looking at the Threads_connected variable, which gives you:

The number of currently open connections.

(which is at the bottom of your image and is 29!)

The show processlist command gives you more information about your active connections!

You need to make sure that you're using a privileged user:

Like the output from the corresponding SHOW statement, the PROCESSLIST table will only show information about your own threads, unless you have the PROCESS privilege, in which case you will see information about other threads, too. As an anonymous user, you cannot see any rows at all.

You will find more relevant information here - the processlist table!

  • 2) What should I do about it?

Congratulate yourself on a site which appears to be running nicely! :-)