diff --git a/HttpServer/Events/OnBeforeReload.php b/HttpServer/Events/OnBeforeReload.php index c32a8dfb..e8ef6a02 100644 --- a/HttpServer/Events/OnBeforeReload.php +++ b/HttpServer/Events/OnBeforeReload.php @@ -24,13 +24,8 @@ class OnBeforeReload extends Callback */ public function onHandler(Server $server) { - Timer::clearAll(); - $event = Snowflake::app()->getEvent(); $event->trigger(Event::SERVER_BEFORE_RELOAD, [$server]); - - $this->clearMysqlClient(); - $this->clearRedisClient(); } } diff --git a/HttpServer/Events/OnWorkerExit.php b/HttpServer/Events/OnWorkerExit.php index 37b303b1..d7b469dc 100644 --- a/HttpServer/Events/OnWorkerExit.php +++ b/HttpServer/Events/OnWorkerExit.php @@ -23,6 +23,8 @@ class OnWorkerExit extends Callback */ public function onHandler($server, $worker_id) { + putenv('state=exit'); + $event = Snowflake::app()->getEvent(); $event->trigger(Event::SERVER_WORKER_EXIT); $event->offName(Event::SERVER_WORKER_EXIT); diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index f4e039e8..258dc78d 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -38,6 +38,7 @@ class OnWorkerStart extends Callback public function onHandler(Server $server, int $worker_id): void { putenv('worker=' . $worker_id); + putenv('state=start'); if ($worker_id >= $server->setting['worker_num']) { $this->onTask($server, $worker_id); diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 90c5e692..2a3727ec 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -51,6 +51,10 @@ abstract class Pool extends Component */ public function Heartbeat_detection() { + if (env('state') == 'exit') { + $this->flush(0); + return; + } if ($this->lastTime == 0) { return; } diff --git a/System/Application.php b/System/Application.php index f756ea7e..4ccc5f3b 100644 --- a/System/Application.php +++ b/System/Application.php @@ -43,6 +43,9 @@ class Application extends BaseApplication public string $id = 'uniqueId'; + public string $state = ''; + + /** * @throws NotFindClassException */