|
@@ -42,11 +42,15 @@ function handle_error($level, $message, $file, $line)
|
|
|
Log::record($trace,Log::ERR);
|
|
|
}
|
|
|
|
|
|
+$waiting_quit = false;
|
|
|
+
|
|
|
function sub_message($channels)
|
|
|
{
|
|
|
+ global $waiting_quit;
|
|
|
+
|
|
|
$redis = new Swoole\Coroutine\Redis();
|
|
|
|
|
|
- while (true)
|
|
|
+ while (!$waiting_quit)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -88,6 +92,7 @@ function sub_message($channels)
|
|
|
Log::record($ex->getMessage(),Log::ERR);
|
|
|
}
|
|
|
}
|
|
|
+ Log::record("sub_message quit",Log::DEBUG);
|
|
|
}
|
|
|
|
|
|
//Co\run(function()
|
|
@@ -103,24 +108,73 @@ function sub_message($channels)
|
|
|
|
|
|
for ($i = 0; $i < $process_count;$i++)
|
|
|
{
|
|
|
- $process = new Swoole\Process(function(Swoole\Process $worker)
|
|
|
+ global $waiting_quit;
|
|
|
+
|
|
|
+ $process = new Swoole\Process(function(Swoole\Process $worker) use (&$waiting_quit)
|
|
|
{
|
|
|
+ Swoole\Process::signal(SIGINT, function($signal_num) use ($worker) {
|
|
|
+ Log::record("signal call 1 = $signal_num, #{$worker->pid}",Log::DEBUG);
|
|
|
+ exit(123);
|
|
|
+ });
|
|
|
+ Swoole\Process::signal(SIGHUP, function($signal_num) use ($worker) {
|
|
|
+ Log::record("signal call 2 = $signal_num, #{$worker->pid}",Log::DEBUG);
|
|
|
+ exit(123);
|
|
|
+ });
|
|
|
+ Swoole\Process::signal(SIGQUIT, function($signal_num) use ($worker) {
|
|
|
+ Log::record("signal call 3 = $signal_num, #{$worker->pid}",Log::DEBUG);
|
|
|
+ exit(123);
|
|
|
+ });
|
|
|
+ Swoole\Process::signal(SIGTERM, function($signal_num) use ($worker,&$waiting_quit)
|
|
|
+ {
|
|
|
+ swoole_async_set(['enable_coroutine' => false]);
|
|
|
+ Log::record("signal call 4 = $signal_num, #{$worker->pid}",Log::DEBUG);
|
|
|
+ $waiting_quit = true;
|
|
|
+ });
|
|
|
+ Swoole\Process::signal(SIGKILL, function($signal_num) use ($worker) {
|
|
|
+ Log::record("signal call 5 = $signal_num, #{$worker->pid}",Log::DEBUG);
|
|
|
+ exit(123);
|
|
|
+ });
|
|
|
+
|
|
|
Base::run_util();
|
|
|
set_error_handler('handle_error');
|
|
|
go(function () {
|
|
|
sub_message(['refill']);
|
|
|
});
|
|
|
|
|
|
- $looper = new processor(true);
|
|
|
- $looper->run();
|
|
|
+// $looper = new processor(true);
|
|
|
+// $looper->run();
|
|
|
|
|
|
}, false, false, true);
|
|
|
|
|
|
- $process->start();
|
|
|
+ $pid = $process->start();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+//Swoole\Process::signal(SIGINT, function($signo) {
|
|
|
+// Log::record("shutdown 1.",Log::DEBUG);
|
|
|
+//});
|
|
|
+//Swoole\Process::signal(SIGHUP, function($signo) {
|
|
|
+// Log::record("shutdown 2.",Log::DEBUG);
|
|
|
+//});
|
|
|
+//Swoole\Process::signal(SIGQUIT, function($signo) {
|
|
|
+// Log::record("shutdown 3.",Log::DEBUG);
|
|
|
+//});
|
|
|
+//Swoole\Process::signal(SIGTERM, function($signo) {
|
|
|
+// Log::record("shutdown 4.",Log::DEBUG);
|
|
|
+//});
|
|
|
+
|
|
|
+//swoole_process::signal(SIGCHLD, function(){
|
|
|
+// //表示子进程已关闭,回收它
|
|
|
+// $status = swoole_process::wait();
|
|
|
+// echo "Worker#{$status['pid']} exit\n";
|
|
|
+//});
|
|
|
+
|
|
|
+//Swoole\Event::wait();
|
|
|
+
|
|
|
for ($i = 0; $i < $process_count;$i++)
|
|
|
{
|
|
|
+ Log::record("process {$i} start wait",Log::DEBUG);
|
|
|
$status = Swoole\Process::wait(true);
|
|
|
Log::record("Recycled #{$status['pid']}, code={$status['code']}, signal={$status['signal']}",Log::DEBUG);
|
|
|
-}
|
|
|
+}
|
|
|
+Log::record("Quit all",Log::DEBUG);
|