I'm running a Windows Server 2016 with an apache 2.4.38 and Maria DB 10.1.38 + PHP 7.3.3

From time to time, I can see (using netstat) that there are many, many, many connections from 127.0.0.1:3306 to 127.0.0.1:64XXX.

An example of netstat :

Proto Local IP        Distant IP     Stat      PID
TCP   127.0.0.1:64896 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64897 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64898 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64899 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64900 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64901 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64902 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64903 127.0.0.1:3306 TIME_WAIT 0
TCP   127.0.0.1:64904 127.0.0.1:3306 TIME_WAIT 0

It's going up to 151 connections ( which is the max limit) and it's blocking the other connections. I don't see any PHP scripts that is "looping" on a SQL request...

I have no trace in the logs/logs-error and I don't know what's causing these many connections.

Do you have any idea of where to start looking or what could be the cause of these connections?

Thanks for your help

1 Answers

0
Rick James On
  • Have your PHP programs disconnect when finished.
  • With rare exceptions, only one connection per PHP script.
  • If there is connection pooling, see if it has a limit higher than 151.
  • Decrease the number of children Apache spawns. (It is rarely useful to spawn hundreds, even if hundreds of users connect.)
  • Speed up the queries so that they finish faster.
  • If you have multiple "users", set a per-user limit lower.

(Almost no one needs 151.)