Swoole 服务器平滑重启

1.新建service.php

#通过swoole_set_process_name函数添加进程名称

<?php
//创建Server对象,监听 127.0.0.1:9501 端口
$server = new Swoole\Server('127.0.0.1', 9502);

/**
 * @param $server
 * 添加进程名称
 */
swoole_set_process_name("live_master");


//监听连接进入事件
$server->on('Connect', function ($server, $fd) {
    echo "Client: Connect.\n";
});

//监听数据接收事件
$server->on('Receive', function ($server, $fd, $reactor_id, $data) {
    $server->send($fd, "Server: {$data}");
});

//监听连接关闭事件
$server->on('Close', function ($server, $fd) {
    echo "Client: Close.\n";
});

//启动服务器
$server->start();

2.创建reload.sh 执行脚本

echo "loading..."
pid=$(pidof live_master)
#pid= `pidof live_master`
echo $pid
kill -usr1 $pid
echo "success loading..."

 

posted @ 2022-07-03 11:56  快乐的在一起  阅读(289)  评论(0编辑  收藏  举报