Pawl icon indicating copy to clipboard operation
Pawl copied to clipboard

How to send command line live output to websocket server?

Open DangerD1024 opened this issue 2 years ago • 0 comments

$app = function (Ratchet\Client\WebSocket $conn) use ($connector, $loop, &$app, $server_id) {
    $conn->on('message', function (\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
        global $server_id;
        $msg = json_decode($msg);
        $proc = popen("ping -t 127.0.0.1",'r');
        if($msg->type=='run') {
            while (!feof($proc))
            {
                echo $read = fread($proc, 4096);
                if($read) {
                    $conn->send($read);
                }
            }
        }
    });

Looks like while (!feof($proc)) blocks main thread... Is there any other way to send live output to websocket server?

DangerD1024 avatar Mar 13 '22 13:03 DangerD1024