加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2021-04-01 11:02:14 所属栏目:MySql教程 来源:网络整理
导读:我无法在stackoverflow上找到解决方案,大多数其他相关主题都与Apache没有先启动并出现此错误有关.我的问题是,在apache运行后,我的一些用户连接到我们的php / mysql网站将收到此错误: PHP Warning: mysql_connect() [function.mysql-connect]:[2002] Only on

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

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读