MySQL – How to Debug ‘Too Many Connections’ Error in PHP

connectionMySQL

I am working right now with PHP website on my client's dedicated server and I get periodically an error too many connections but ~5 users are browsing this page.

In phpMyAdmin I can see that max connections variable is set to 400.

On our local MySQL server in my corporation we have max connections set to 200 and other mates uses in the same time this server.

I heard that on their server some other web is using the same MySQL with big trafiic.

Here are my questions:

  • How to debug this problem?
  • Can I look into some list of SQL queries that was executed in last 10 minutes to check if it is our problem or their?

Best Answer

The symptoms you describe point to persistent connections. In some setups PHP does not handle persistent connections very well: it tends to open new connections rather than reuse the existing ones. I suggest you disable this feature and see if the issue persists:

If you notice an improvement, you can try to fine tune persistent calls or get rid of them permanently.