Это полный код:
Код: Выделить всё
public function run()
{
if ($this->_type == 'ws') {
$this->_server = new swoole_websocket_server($this->_host, $this->_port, $this->_mode, $this->_socketType);
} else {
$this->_server = new swoole_websocket_server($this->_host, $this->_port, $this->_mode, $this->_socketType | SWOOLE_SSL);
}
$this->_server->set($this->_config);
$this->_server->on('open', [$this, 'onOpen']);
$this->_server->on('message', [$this, 'onMessage']);
$this->_server->on('task', [$this, 'onTask']);
$this->_server->on('finish', [$this, 'onFinish']);
$this->_server->on('close', [$this, 'onClose']);
$this->_server->on('shutdown', [$this, 'onShutdown']);
$this->_server->start();
if (extension_loaded("pcntl")) {
// pcntl_signal_dispatch();
//Add signal handlers to shut down the bot correctly if its getting killed
pcntl_signal(SIGTERM, [$this, "signal_handler"]);
pcntl_signal(SIGINT, [$this, "signal_handler"]);
pcntl_signal(SIGUSR1, [$this, "signal_handler"]);
pcntl_signal(SIGHUP, [$this, "signal_handler"]);
} else {
die("Please make sure the pcntl PHP extension is enabled.\n");
}
}