MySQL / PHP错误:[2002]通常只允许使用每个套接字地址(协议/网络地址/端口)

前端之家收集整理的这篇文章主要介绍了MySQL / PHP错误:[2002]通常只允许使用每个套接字地址(协议/网络地址/端口)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我无法在stackoverflow上找到解决方案,大多数其他相关主题都与Apache没有先启动并出现此错误有关.我的问题是,在apache运行后,我的一些用户连接到我们的PHP / mysql网站将收到此错误

PHP Warning:  MysqL_connect() [function.MysqL-connect]:
[2002] Only one usage of each socket address (protocol/network address/port)
is normally permitted.

这似乎是完全随机的,当我监视Apache的工作线程时,通常有许多空闲工作者可以接受新的连接/请求.

我的网站运行在Windows XP SP3,Xampp 1.7.7,四核,4GB内存,1TB HD,PHP / MysqL规范:

Apache / 2.2.21(Win32)mod_ssl / 2.2.21 OpenSSL / 1.0.0e PHP / 5.3.8 mod_perl / 2.0.4 Perl / v5.10.1

任何帮助我应该改变我的任何配置,以使其消失将不胜感激.我已经看过谷歌,甚至在Xampp论坛上,但是大多数人在启动Apache之前都会遇到这个问题,但是当用户遇到这个错误时,Apache运行正常.

最佳答案
错误实际上并非来自MysqL,而是from Windows itself

When a connection is closed,on the side that is closing the connection the 5 tuple
{ Protocol,Local IP,Local Port,Remote IP,Remote Port} goes into a TIME_WAIT state for 240 seconds by default.

In this case,the protocol is fixed – TCP

The local IP,remote IP and remote PORT are also typically fixed. So the variable is the local port.

What happens is that when you don’t bind a port in the range 1024-5000 is used.
So roughly you have 4000 ports. If you use all of them in 4 minutes – meaning roughly you
make 16 web service calls per second for 4 minutes you will exhaust all the ports. That is the cause of this exception.

换句话说,您已经耗尽了动态范围内的端口.那可能不应该发生.你在这里处理多少并发用户

链接博客解决方法

>通过注册表编辑增加动态端口范围.
>通过注册表编辑减少系统希望在TIME_WAIT中花费的连接的时间.
>运行一些代码来执行上述注册表编辑而不使用regedit.

各种各样的解决方法

另见this question on the Visual Studio forums,其解释如下:

The port will be locked for another minute or two to catch all packets which might have been sent before the application was terminated but haven’t arrived yet. In Winsock API you can set socket option SO_REUSEADDR to resolve this (also this option can be set in .NET Socket class),but TcpListener is too high-level and doesn’t let you set this option.

连接MysqL的底层代码或处理Apache连接的代码很可能不会尝试使用SO_REUSEADDR.

我敢打赌,改变keepalive超时会对此产生直接影响.即使从理论上减少它释放套接字,Windows也不同意并保留套接字保留.

原文链接:https://www.f2er.com/mysql/433577.html

猜你在找的MySQL相关文章