大网数据广告活动
服务器运维问答

Azure MySQL in-app: Only one usage of each socket address is normally permitted

· 52CE 我爱测

I'm running an app-service on Azure with a PHP application and a MySQL in-app database on it. This app service has a lot of small requests coming in (i.e. to get or update a leaderboard for a game). Often, I see the following war…

问题原文

原帖链接 · Jan Discart · CC BY-SA 4.0

I'm running an app-service on Azure with a PHP application and a MySQL in-app database on it. This app service has a lot of small requests coming in (i.e. to get or update a leaderboard for a game).

Often, I see the following warning coming by in the log file of the PHP application:

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

I receive several complaints from players that they fail to update their score on the leaderboards, which I connect to seeing this warning a lot in the logs. I traced the issue being that connections are being held in the TIME_WAIT state for too long on the level of the operating system, or that the range of ports that can be used is simply too small to handle more connections.

How can I adjust this on Azure so that this warning is either gone, or a lot less frequent? I use the close() function on my mysqli objects to clear the connection, but as I understand correctly, this doesn't immediately release the underlying resources in the OS.

Thanks in advance!

已采纳解答

原帖链接 · Piotr P. Karwasz · CC BY-SA 4.0

The problem is in the way TCP/IP connections close:

  • You ask to close the connection (FIN),
  • The server acknowledges it received your request (ACK) and also asks to close its side (FIN),
  • You acknowledge (ACK) that and wait around 4 minutes (TIME_WAIT state) to be sure that no packets sent by the server and delayed by the network will arrive. During this time you can not use the same port to connect to the server.

mysqli probably uses several source ports, but even if it used all of them, the limit is around 270 connections per second.

To solve your problem, enable persistent connections in PHP and don't close them. An old connection will be reused whenever possible.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。