Reasons for send_fail in status

Phenomenon:

When running the status command, seeing send_fail situations, what is the reason?

Answer:

Having send_fail is generally not a major issue, usually caused by the client actively closing the connection or the client being unable to receive data, resulting in data transmission failure.

There are two reasons for send_fail:

  1. When calling the send interface to send data to the client and finding that the client has already disconnected, the send_fail count increases by 1. Since this is due to the client actively disconnecting, it is considered normal and can generally be ignored.

  2. The speed of data sent by the server exceeds the speed of the client receiving data, leading to a continuous backlog of data in the server buffer (Workerman establishes a sending buffer for each client). If the buffer size exceeds the limit (TcpConnection::$maxSendBufferSize defaults to 1M), the data will be discarded, triggering the onError event (if any) and causing the send_fail count to increase by 1.

For example, after minimizing the browser, the JS may pause execution, causing the browser to pause receiving data from the server, resulting in data being backlogged in the buffer for an extended period. Once the limit is exceeded, each call to send will result in an increase of the send_fail count by 1.

Summary:

Generally, send_fail caused by the client disconnecting does not need to be worried about.

If send_fail is caused by the client stopping data reception, it is necessary to check whether the client is functioning normally.

If the client’s data reception speed continues to be lower than the server's sending speed, consider optimizing the business process or enhancing client performance. If the issue is due to bandwidth causing poor transmission, consider increasing server bandwidth.