<?php
namespace app\Console;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class WebSocket extends Command
{
// Server 实例
protected $server;
protected function configure(){
$this->setName('websocket:start')->setDescription('Start Web Socket Server!');
}
protected function execute(Input $input, Output $output){
// 监听所有地址,监听 10000 端口
$this->server = new \swoole_websocket_server('0.0.0.0', 9997);
$this->server->set([
'max_conn' => 50,
'max_request' => 50,
'daemonize' => 1
]);
// 设置 server 运行前各项参数
// 调试的时候把守护进程关闭,部署到生产环境时再把注释取消
// $this->server->set([
// 'daemonize' => true,
// ]);
// 设置回调函数
$this->server->on('Open', [$this, 'onOpen']);
$this->server->on('Message', [$this, 'onMessage']);
namespace app\Console;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class WebSocket extends Command
{
// Server 实例
protected $server;
protected function configure(){
$this->setName('websocket:start')->setDescription('Start Web Socket Server!');
}
protected function execute(Input $input, Output $output){
// 监听所有地址,监听 10000 端口
$this->server = new \swoole_websocket_server('0.0.0.0', 9997);
$this->server->set([
'max_conn' => 50,
'max_request' => 50,
'daemonize' => 1
]);
// 设置 server 运行前各项参数
// 调试的时候把守护进程关闭,部署到生产环境时再把注释取消
// $this->server->set([
// 'daemonize' => true,
// ]);
// 设置回调函数
$this->server->on('Open', [$this, 'onOpen']);
$this->server->on('Message', [$this, 'onMessage']);