The ERROR:
mysqli_real_connect(): (HY000/2002): Only one usage of each socket address (protocol/network address/port) is normally permitted.
However, it appears I have enough ports.
DETAILS:
I have a MySQL
server that has been running for several months without issue. I am running Windows 10, PHP 7.0 and MySQL 5.7. This is a busy server with a high volume of transactions per hour.
For about a week now, I have been getting an excessive volume of:
mysqli_real_connect(): (HY000/2002): Only one usage of each socket address (protocol/network address/port) is normally permitted.
I have tried the common suggestions, which have worked for me on other machines.
TcpTimedWaitDelay = 30 and MaxUserPort = 65534
I also added:
TcpNumConnections = 16777214 and TcpMaxDataRetransmissions = 5.
I am able to confirm the max ports and timeout via netsh. Further, when I run netstat /abno I consistently see fewer than 1000 ports in use. However, I am still getting the above error. So it appears that the machine is not even using all of the ports.
In my .ini
, I have a connection limit of 10,000
.
So this looks to be a windows issue rather than an issue with MySQLi. (Possibly due to a recent windows 10 update) - though could be due to sockets not being closed properly.
Fix 1: Make more ports available
Launch regedit.exe and browse to: HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort
There is a string value, which by default is set to 5000 - this determines the maximum number of available ports. You can change this to anything upto 65534.
Make sure you restart your web server (and preferably your entire machine) for changes to take effect
Fix 2: Explicitly specify localhost IP
Any connections to localhost should be specified as 127.0.0.1
, rather than localhost
Fix 3: Confirm no duplicated services
Check to make sure there any not multiple instances of your web server running, or multiple calls to open a connection to said server - as this will lock ports. Open services.msc - if there are duplicated services, you should remove one instance.
Fix 4: Are you closing connections properly?
If you can, please post your code so that we have a better understanding of whats happening - and whether or not connections are being closed properly, and thus freeing a socket/port
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With