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

MySQLPHP错误:[2002]通常只允许使用每个套接字地址(协议网络地址端口),第1张

概述我无法在stackoverflow上找到解决方案,大多数其他相关主题都与Apache没有先启动并出现此错误有关.我的问题是,在apache运行后,我的一些用户连接到我们的php / mysql网站将收到此错误:PHP Warning: mysql_connect() [function.mysql-connect]: [2002] Only one usa

我无法在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也不同意并保留套接字保留.

总结

以上是内存溢出为你收集整理的MySQL / PHP错误:[2002]通常只允许使用每个套接字地址(协议/网络地址/端口)全部内容,希望文章能够帮你解决MySQL / PHP错误:[2002]通常只允许使用每个套接字地址(协议/网络地址/端口)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1167167.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存