Php socket blocking mode problem

The

code is as follows. The server will return data several times within 3 seconds. I want the following loop to be terminated after more than 3 seconds. What should I do?

 while ($mes = socket_read($socket, 1024)) {
//xxxxx
}
Jun.25,2021

record a start time outside the loop, judge the running time within the loop, and break the loop when the condition is exceeded

Menu