Error “mysqli::real_connect(): (HY000/2002): Only … permitted.”

好久不见. 提交于 2020-01-13 09:34:17

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/48043528/error-mysqlireal-connect-hy000-2002-only-permitted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!