workerman
workerman copied to clipboard
Compression on Websocket server
Hi thanks for Workerman, how to enable messages compression on websocket server?
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.