1

I noticed that my php errorlog contained following lines: PHP Fatal error: Uncaught PDOException: SQLSTATE[08004] [1040] Too many connections in...

Is there a way to see which files are causing this error? So, for example, files that leave connection open?

My point here is that this error appears in the log only when the number of connections is exceeded, so the file mentioned in the errorlog is not necessarily the cause of the error itself (other files may have increased the number of connections).

tried looking into mysql processlists but nothing there… mysql> show status like '%onn%'; mysql> show processlist;

tonsaa
  • 41
  • 3
  • In PHP, **NO files** leave the connection open (unless you are using the persistent connection which you shouldn't anyway). It's not a problem with leaving it open. it's a problem with each file opening more than one connection. – Your Common Sense Nov 10 '22 at 10:57
  • @YourCommonSense PHP files do leave MySQL connections open if you don't explicitly close them, though they are closed automatically when the "wait_timeout" is reached. – Vincent Jun 14 '23 at 21:42
  • @Vincent Where did you get that? PHP does close the connection [EXPLICITLY](https://github.com/php/php-src/blob/96ea06a1d9b115a138bd9e16a3ecc7901ae3abf6/ext/mysqli/mysqli.c#L90) – Your Common Sense Jun 15 '23 at 03:38
  • @YourCommonSense it depends. I'm not sure what exactly the criteria is, but they do stay open when the server is under heavy load. – Vincent Jun 16 '23 at 04:05
  • @Vincent may be that server just uses persistent connections – Your Common Sense Jun 16 '23 at 05:07
  • @YourCommonSense That's what I thought too, but I confirmed that it's not. It seems like if a page load takes longer than a second or so, then the connection will remain open until it reaches wait_timeout, but if the page loads quickly, then the connection also closes right away. But like I said, it only seems to be a problem under heavy load. Almost like they get bottlenecked and that's preventing them from closing. (when I say heavy load, I mean many users, even though my CPU and RAM are nowhere near exhausted, so it's not a hardware limitation. Maybe it's configuration) – Vincent Jun 16 '23 at 19:11

0 Answers0