I use Swoole as a WebSocket server. Once per second I need to broadcast a message to all connected WS clients.
Naive approach: I set a server timer $server->tick()
prior to launching a server:
$this->server->tick(1000, function () {
$message = 'hello';
foreach ($this->server->connections as $fd) {
$this->server->push($fd, $message);
}
});
Got errors:
[2020-05-05 12:23:56 #21985.2] ERROR swServer_tcp_send (ERRNO 9009) can't send data to the connections in master process
What is the correct way to push WebSocket messages not from a Master, but from a Worker process?