swoole 官方明确 swoole 自定义进程 addProcess 不支持热重启,但是换个思路可以实现
public function main(){
$this->server = new Server("0.0.0.0",20000);
$this->server->set([
"worker_num"=>2,
"daemonize"=>true,
"reload_async"=>true,
]);
$this->startProcess($this->server);
foreach ($this->events as $event){
$this->server->on($event,[$this,$event]);
}
$this->server->start();
}
public function startProcess(Server $server){
$server->addProcess(new Process(function(Process $process){
swoole_set_process_name("z:process");
$run = true;
require "./test.php";
pcntl_signal(SIGUSR1,function ($signo){
file_put_contents("/data/wwwroot/php-cli/process.log",time()." {$signo}\n",FILE_APPEND);
require "./test.php";
});
while($run){
pcntl_signal_dispatch();
test();
}
}));
}
// 通过外部发送 SIGUSR1 实现杀死自定义进程,然后swoole的manager 会重新拉起一个新的Process.. 并不会丢失原有的业务。。
网友评论