workerman icon indicating copy to clipboard operation
workerman copied to clipboard

Compression on Websocket server

Open Vladislavik opened this issue 2 years ago • 1 comments

Hi thanks for Workerman, how to enable messages compression on websocket server?

Vladislavik avatar Feb 22 '22 15:02 Vladislavik

Workerman has no option to compression message. However, you can compress the message with the following code.

use Workerman\Protocols\Websocket;
$worker = new Worker('ws://0.0.0.0:8888');
$worker->onConnect = function($connection) {
    $connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
};
$worker->onMessage = function($connection, $data) {
    $connection->send(gzcompress($data));// or gzdeflate($data) or gzencode($data);
};

But I don't know how to uncompress the message with js.

walkor avatar Feb 23 '22 02:02 walkor