PHP/mySQL: how to debug a 'too many connections' error?

Solution 1:

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:

  • At code level: find calls to mysql_pconnect() and replace them with mysql_connect().
  • At configuration level: find the mysql.allow_persistent directive and set it to false.

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