Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of server interruption caused by abnormal client shutdown in php socket programming

Shulou Source: shulou.com Published: 2022-06-02 04:54:46 10月18日 Update

This article mainly explains how to solve the problem of server interruption caused by abnormal client closure in php socket programming. The explanation in this article is simple and clear and easy to learn and understand. Please follow Xiaobian's train of thought to study and learn how to solve the problem of server interruption caused by abnormal client closure in php socket programming.

The reasons are as follows:

1.socket_recv supports a variety of flag for different scenarios

2.socket_recv can detect socket shutdown (for example, socket is closed on the peer)

Return value: $return_value=socket_recv (...)

Meaning: > 0 indicates the number of bytes received

= 0, an error occurred, socket closed

= false, no data, socket not closed.

Socket_read cannot determine whether the socket has been disconnected.

Test process:

Start the server, and then start the client: you can communicate normally.

Kill leaves the client end, and as a result, the server side can only read an empty string.

The test code is as follows:

File: bug1_server.php

File:bug1_client.php

The correct code is: (file: debug1_server.php)

Thank you for reading, the above is the content of "how to solve the problem of server interruption caused by client abnormal closure in php socket programming". After the study of this article, I believe you have a deeper understanding of how to solve the problem of server interruption caused by client abnormal closure in php socket programming, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Service client client problem programming information server learning generation code content that is situation side length test different reason meaning scenario Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS NVidia MariaDB Apple