0

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

Foldras
  • 1
  • 1
  • check here for more information https://stackoverflow.com/questions/5062839/mysql-time-wait-too-many-connections-problem – Anouar BAKRI Apr 04 '19 at 13:02
  • Each page load makes Apache boot a new PHP process, which (probably) opens a connection to MySQL. Try to use persistent connections, so that current handles are reused rather than create a new one each time. It's difficult to tell you why it happens, but I stopped using Apache ages ago due to many oddities I encountered. Sadly, you're not using *nix and that prevents you from using nginx and php-fpm (which is not only preferred way, but the most performant way as well). Consider using a virtual machine and ditching apache under windows. – Mjh Apr 04 '19 at 13:29

1 Answers1

0
  • 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.)

Rick James
  • 135,179
  • 13
  • 127
  • 222