From 5cbf7924742c573811d89be6ef60145c2c8b88a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 16:08:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Events/OnStart.php | 5 ++--- HttpServer/Events/OnWorkerStart.php | 2 +- System/Snowflake.php | 11 +++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/HttpServer/Events/OnStart.php b/HttpServer/Events/OnStart.php index 73599a8a..e5fad17a 100644 --- a/HttpServer/Events/OnStart.php +++ b/HttpServer/Events/OnStart.php @@ -18,9 +18,8 @@ class OnStart extends Callback */ public function onHandler($server) { - $time = storage('socket.sock'); - Snowflake::writeFile($time, $server->master_pid); - + Snowflake::setProcessId($server->master_pid); + $event = Snowflake::app()->event; if ($event->exists(Event::SERVER_EVENT_START)) { $event->trigger(Event::SERVER_EVENT_START, null, $server); diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 662056cd..df54a916 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -31,7 +31,7 @@ class OnWorkerStart extends Callback */ public function onHandler(Server $server, $worker_id) { - Snowflake::setProcessId($server->worker_pid); + Snowflake::setWorkerId($server->worker_pid); $get_name = $this->get_process_name($server, $worker_id); if (!empty($get_name) && !Snowflake::isMac()) { diff --git a/System/Snowflake.php b/System/Snowflake.php index 7ebfd6c8..01029f3b 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -130,6 +130,17 @@ class Snowflake } + /** + * @param $workerId + * @return false|int|mixed + * @throws Exception + */ + public static function setWorkerId($workerId) + { + return self::writeFile(storage($workerId . '.sock', 'worker'), $workerId); + } + + /** * @param $fileName * @param $content