MySQL的/ PHP的错误:[2002]每个套接字地址(协议/网络地址/端口)的一个用法通常被允许 [英] MySQL/PHP Error:[2002] Only one usage of each socket address (protocol/network address/port) is normally permitted

查看:202
本文介绍了MySQL的/ PHP的错误:[2002]每个套接字地址(协议/网络地址/端口)的一个用法通常被允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一个解决这个已经在计算器,其他大多数相关话题曾与阿帕奇不先开始,收到此错误的事情。我的问题是,Apache的运行后我的一些用户连接到我们的PHP / MySQL的网站将收到此错误:

  PHP的警告:mysql_connect()函数[function.mysql连接]:
[2002]每个套接字地址的一个用法(协议/网络地址/端口)
通常是允许的。

这似乎是完全随机的,当我监视我的工作线程的Apache,通常有大量的闲散人员可以接受新的连接/请求。

我的网站在Windows XP SP3,Xampp时1.7.7,四核,内存4gigs,1TB硬盘,规格为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

这是我应该在我的任何配置的改变,使这个消失将是极大的AP preciated任何帮助。我看对谷歌,甚至对于Xampp论坛,但大多数人在发布之前的Apache遇到此问题,但是Apache对我来说运行良好,当用户遇到这个错误。


解决方案

错误实际上不是从MySQL来了,但的从Windows本身


  

当一个连接被关闭,在被关闭连接的5元组的一侧
  {协议,本地IP,本地端口,远程IP,远程端口}进入240秒默认情况下,TIME_WAIT状态。


  
  

在这种情况下,该协议是固定的 - TCP


  
  

本地IP,远程IP和远程端口通常也固定。因此该变量是本地端口。


  
  

会发生什么事是,当你没有在1024-5000的范围内的端口绑定使用。
  所以,大概有4000端口。如果您使用的所有的人都在4分 - 大致意思是你
  每秒钟16 Web服务调用4分钟,你会用尽所有的端口。此异常的原因。


在换句话说,你已经在动态范围用完端口。这可能不应该发生。有多少并发用户,你这里处理?

链接的博客有解决方法:


  1. 增加通过注册表编辑动态端口范围。

  2. 降低系统要连接,通过注册表编辑花了 TIME_WAIT 的时间。

  3. 运行有点code做上述注册表编辑注册表编辑器没有

什么解决方法多种多样!

又见<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/a595c417-10dc-4b06-b4c2-490c8abe776d\"相对=nofollow>这个问题上的Visual Studio论坛,这也解释了:


  

端口将被锁定为另一个两分钟赶上这可能会申请被终止前已经发送,但还没有到达的数据包。在的Winsock API可以设置套接字选项SO_REUSEADDR来解决这个(也该选项可以在.NET Socket类进行设置),但的TcpListener太高层次,不会让你设置这个选项。


这很可能是潜在的code连接到MySQL或code处理Apache中的连接是不是想用 SO_REUSEADDR

我会打赌你的存活时间超时的变化在这里产生了直接影响。尽管它减少的理论上的释放了插座时,Windows不同意,并保持插座保留。

I couldn't find a solution to this already on stackoverflow, most other related topics had to do with Apache not starting first and getting this error. My issue is that after apache is running some of my users that are connected to our php/mysql website will receive this error:

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

This seems to be totally random and when I monitor my worker threads for Apache, there are typically lots of idle workers available to accept new connections/requests.

My Site is running on Windows XP SP3, Xampp 1.7.7, Quad Core, 4gigs of RAM, 1TB HD, Specs for 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

Any help on what I should change in any of my configurations to make this go away would be greatly appreciated. I've looked on google and even on Xampp forums but most people experience this issue prior to launching Apache, but Apache is running fine for me when users are experiencing this error.

解决方案

The error isn't actually coming from MySQL, but 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.

In other words, you've run out of ports in the dynamic range. That probably shouldn't be happening. How many concurrent users are you dealing with here?

The linked blog has workarounds:

  1. Increase the dynamic port range through registry editing.
  2. Reduce the time the system wants connections to spent in TIME_WAIT through registry editing.
  3. Run a bit of code to do the above registry edit without regedit.

What a wide variety of workarounds!

See also this question on the Visual Studio forums, which explains:

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.

It's very likely that the underlying code to connect to MySQL or the code that handles connections in Apache isn't trying to use SO_REUSEADDR.

I'm going bet that your changing of the keepalive timeout had a direct impact here. Even though reducing it theoretically frees up the socket, Windows disagrees and keeps the socket reserved.

这篇关于MySQL的/ PHP的错误:[2002]每个套接字地址(协议/网络地址/端口)的一个用法通常被允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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