diff --git a/http-server/Constant.php b/http-server/Constant.php index 92802d4e..5710e84b 100644 --- a/http-server/Constant.php +++ b/http-server/Constant.php @@ -13,6 +13,7 @@ class Constant const START = 'Start'; const SHUTDOWN = 'Shutdown'; + const BEFORE_SHUTDOWN = 'beforeShutdown'; const WORKER_START = 'WorkerStart'; const WORKER_STOP = 'WorkerStop'; const WORKER_EXIT = 'WorkerExit'; diff --git a/http-server/Events/OnBeforeShutdown.php b/http-server/Events/OnBeforeShutdown.php new file mode 100644 index 00000000..d9614699 --- /dev/null +++ b/http-server/Events/OnBeforeShutdown.php @@ -0,0 +1,18 @@ +setProcessName(sprintf('start[%d].server', $server->master_pid)); + $this->setProcessName(sprintf('start[%d].server', $server->master_pid)); - $this->eventDispatch->dispatch(new OnStart($server)); + $this->eventDispatch->dispatch(new OnStart($server)); + } + + + /** + * @param \Swoole\Server $server + */ + public function onBeforeShutdown(\Swoole\Server $server) + { + $this->eventDispatch->dispatch(new OnBeforeShutdown($server)); } - /** * @param \Swoole\Server $server */ @@ -46,5 +55,4 @@ class OnServer extends Server } - } diff --git a/http-server/SInterface/OnBeforeShutdown.php b/http-server/SInterface/OnBeforeShutdown.php new file mode 100644 index 00000000..9e70758b --- /dev/null +++ b/http-server/SInterface/OnBeforeShutdown.php @@ -0,0 +1,8 @@ + [OnServerWorker::class, 'onWorkerStart'], - Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'], - Constant::WORKER_STOP => [OnServerWorker::class, 'onWorkerStop'], - Constant::WORKER_ERROR => [OnServerWorker::class, 'onWorkerError'], - Constant::MANAGER_START => [OnServerManager::class, 'onManagerStart'], - Constant::MANAGER_STOP => [OnServerManager::class, 'onManagerStop'], - Constant::BEFORE_RELOAD => [OnServerReload::class, 'onBeforeReload'], - Constant::AFTER_RELOAD => [OnServerReload::class, 'onAfterReload'], - Constant::START => [OnServer::class, 'onStart'], - Constant::SHUTDOWN => [OnServer::class, 'onShutdown'], + Constant::WORKER_START => [OnServerWorker::class, 'onWorkerStart'], + Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'], + Constant::WORKER_STOP => [OnServerWorker::class, 'onWorkerStop'], + Constant::WORKER_ERROR => [OnServerWorker::class, 'onWorkerError'], + Constant::MANAGER_START => [OnServerManager::class, 'onManagerStart'], + Constant::MANAGER_STOP => [OnServerManager::class, 'onManagerStop'], + Constant::BEFORE_RELOAD => [OnServerReload::class, 'onBeforeReload'], + Constant::AFTER_RELOAD => [OnServerReload::class, 'onAfterReload'], + Constant::START => [OnServer::class, 'onStart'], + Constant::BEFORE_SHUTDOWN => [OnServer::class, 'onBeforeShutdown'], + Constant::SHUTDOWN => [OnServer::class, 'onShutdown'], ]; - - private array $eventInterface = [ - OnReceiveInterface::class => 'receive', - OnPacketInterface::class =>'packet', - OnHandshakeInterface::class => 'handshake', - OnMessageInterface::class =>'message', - OnConnectInterface::class =>'connect', - OnCloseInterface::class =>'close', - OnDisconnectInterface::class =>'disconnect' - ]; - + private array $eventInterface = [ + OnReceiveInterface::class => 'receive', + OnPacketInterface::class => 'packet', + OnHandshakeInterface::class => 'handshake', + OnMessageInterface::class => 'message', + OnConnectInterface::class => 'connect', + OnCloseInterface::class => 'close', + OnDisconnectInterface::class => 'disconnect' + ]; /** @@ -189,9 +188,9 @@ class ServerManager } $name = $customProcess->getProcessName($soloProcess); - if (is_enable_file_modification_listening()) { - scan_directory(directory('app'), 'App'); - } + if (is_enable_file_modification_listening()) { + scan_directory(directory('app'), 'App'); + } $system = sprintf('%s.process[%d]', Config::get('id', 'system-service'), $soloProcess->pid); if (Kiri::getPlatform()->isLinux()) {