错误"mysqli :: real_connect():( HY000/2002):仅允许...." [英] Error "mysqli::real_connect(): (HY000/2002): Only ... permitted."

查看:161
本文介绍了错误"mysqli :: real_connect():( HY000/2002):仅允许...."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

mysqli_real_connect():(HY000/2002):每个套接字仅使用一种 地址(协议/网络地址/端口)通常是允许的.

mysqli_real_connect(): (HY000/2002): Only one usage of each socket address (protocol/network address/port) is normally permitted.

但是,看来我有足够的端口.

详细信息:

我有一个MySQL服务器已经运行了几个月,没有出现任何问题.我正在运行 Windows 10,PHP 7.0和MySQL 5.7 .这是一台繁忙的服务器,每小时有大量事务.

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):每个套接字仅使用一种 地址(协议/网络地址/端口)通常是允许的.

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

我还添加了:

TcpNumConnections = 16777214 and TcpMaxDataRetransmissions = 5.

我能够通过netsh确认最大端口数和超时.此外,当我运行netstat/abno时,我始终看到使用的端口少于1000个.但是,我仍然收到上述错误.因此,看来机器甚至都没有使用所有端口.

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.

在我的.ini中,我有一个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.

修复1:使更多端口可用

启动 regedit.exe 并浏览至: HKLM \ System \ CurrentControlSet \ Services \ Tcpip \ Parameters \ MaxUserPort

有一个字符串值,默认情况下设置为5000-这确定了可用端口的最大数量.您最多可以将其更改为65534.

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.

请确保您重新启动Web服务器(最好是重启整个计算机),以使更改生效

Make sure you restart your web server (and preferably your entire machine) for changes to take effect

修复2:明确指定本地主机IP

与本地主机的任何连接都应指定为127.0.0.1,而不是localhost

Any connections to localhost should be specified as 127.0.0.1, rather than localhost

修复3:确认没有重复的服务

检查以确保您的Web服务器没有正在运行的多个实例,或者有多个调用打开了与该服务器的连接-因为这将锁定端口.打开 services.msc -如果服务重复,则应删除一个实例.

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.

修复4:您是否正确关闭了连接?

如果可以的话,请发布您的代码,以便我们对正在发生的事情有更好的了解-以及是否正确关闭了连接,从而释放了套接字/端口

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

这篇关于错误"mysqli :: real_connect():( HY000/2002):仅允许...."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆