Socket_read problem in php

I wrote a test socket link test server-side php script.
after being executed in linux, the content returned by the server can be returned. But later, it is judged that the code that exits in more than 3 seconds will not be executed, and the php script process will be there all the time. How should I deal with it? I"m in a bit of a hurry, and the question may be a little unclear. Sorry.)

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
        exit;
    }
    $result = socket_connect($socket, $host, $port);
    if ($result === false) {
        exit;
    }
    socket_write($socket, $str, strlen($str));//socket.
    $time = time();
    while($king=socket_read($socket,1024)){
        echo $king;
        if((time()-$time)>3){
            echo "";
            socket_write($socket, $str, strlen($exit));
            exit;
        }
    }
Jun.10,2021

this is not read EOF, socket_read is blocked

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4bec3-43b99.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4bec3-43b99.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?