swoole 热重启

参考原文 https://blog.csdn.net/ldy3243942/article/details/40712475

代码用的原来只是自己加了一些操作流程

 swoole_reload_server.php

serv = new swoole_server("0.0.0.0", 9501);
        $this->serv->set(array(
            'worker_num' => 8,
            'daemonize' => false,
            'max_request' => 10000,
            'dispatch_mode' => 2,
            'debug_mode'=> 1,
        ));
        $this->serv->on('Start', array($this, 'onStart'));
        $this->serv->on('WorkerStart', array($this, 'onWorkerStart'));
        $this->serv->on('Connect', array($this, 'onConnect'));
        $this->serv->on('Receive', array($this, 'onReceive'));
        $this->serv->on('Close', array($this, 'onClose'));
        $this->serv->start();
    }
    public function onStart( $serv ) {
        echo "Start\n";
        cli_set_process_title("reload_master");
    }
    public function onWorkerStart( $serv , $worker_id) {
        require_once "reload_page.php";
        Test();
    }
    public function onConnect( $serv, $fd, $from_id ) {
        echo "Client {$fd} connect\n";

    }
    public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {
        echo "Get Message From Client {$fd}:{$data}\n";
    }
    public function onClose( $serv, $fd, $from_id ) {
        echo "Client {$fd} close connection\n";
    }
}
new Server();

reload.sh

echo "Reloading..."
cmd=$(pidof reload_master)

kill -USR1 "$cmd"
echo "Reloaded"

reload_page.php 


操作流程如下

swoole 热重启_第1张图片


这个时候 reload_page.php 函数还是

swoole 热重启_第2张图片


大神代码里的注释试修改这个 那么我们开始修改 再执行.sh脚本 看看是否有变化

尝试修改为

swoole 热重启_第3张图片

然后执行脚本呢  脚本 记得 chmod a+x 授权一下 

swoole 热重启_第4张图片

发现这个原来的sever改变了 

swoole 热重启_第5张图片

变成了 i‘m  fun  这里没加换行  大概就这样实现了热重启 


你可能感兴趣的:(php,swoole)