Swoole\Http\Server
服务被 kill 后, 如何安全等待事件执行完成.
$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->set(['daemonize' => false]);
$http->on('start', function () {
l('server pid: ' . getmypid());
file_put_contents('tmp.pid', getmypid());
swoole_set_process_name('swoole_master');
});
$http->on('request', function (\Swoole\Http\Request $request, $response) {
log($request->server);
$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->on('workerstop', function () use($c) {
\Swoole\Timer::after(10000, function () {
log('task call');
});
\Swoole\Event::wait();
log('time wait exit');
});
$http->start();
kill $MASTER_PID
执行 kill 后 \Swoole\Event::wait()
不起作用.
求思路!!
Swoole
提供了柔性终止/重启的机制,只需要向Server
发送特定的信号,Server
的Worker
进程可以安全的结束参考一下文档吧
https://wiki.swoole.com/wiki/...
https://wiki.swoole.com/wiki/...