项目运行中,直接重启会导致数据丢失等,因此要采用平滑重启。
1、修改当前进程名称
public function __construct(){
$this->ws = new swoole_websocket_server(self::HOST, self::PORT);
$this->ws->listen(self::HOST, self::CHART_PORT,SWOOLE_SOCK_TCP);
$this->ws->set([
'enable_static_handler' => true,
'document_root' => "/www/wwwroot/swoole.demo/tp5/public",//程序静态文件目录
'worker_num' => 4,
'task_worker_num' => 4,
]);
$this->ws->on("start", [$this, 'onStart']);
$this->ws->on("open", [$this, 'onOpen']);
$this->ws->on("message", [$this, 'onMessage']);
$this->ws->on("workerstart", [$this, 'onWorkerStart']);
$this->ws->on("request", [$this, 'onRequest']);
$this->ws->on("task", [$this, 'onTask']);
$this->ws->on("finish", [$this, 'onFinish']);
$this->ws->on("close", [$this, 'onClose']);
$this->ws->start();
}
public function onS
tart($server){
swoole_set_process_name('live_master');
}
2、编写shell脚本,并执行
echo "loading..."
#live_master 当前进程名称
pid=`pidof live_master`
echo $pid
kill -USR1 $pid
echo "loading success"
执行成功后原进程会显示重启成功