From 9eb660bff841c4d488f06bf078aa03fc4e7ecdec Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Tue, 4 May 2021 03:43:22 +0800 Subject: [PATCH] modify --- HttpServer/Events/OnWorkerStart.php | 8 ++++---- System/Runtime.php | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index cc5e0308..9ae1c889 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -8,6 +8,7 @@ use Exception; use HttpServer\Abstracts\Callback; use Snowflake\Event; use Snowflake\Exception\ConfigException; +use Snowflake\Runtime; use Snowflake\Snowflake; use Swoole\Coroutine; use Swoole\Coroutine\System; @@ -34,14 +35,13 @@ class OnWorkerStart extends Callback putenv('worker=' . $worker_id); $annotation = Snowflake::app()->getAnnotation(); + $annotation->setLoader(unserialize(file_get_contents(storage(Runtime::CACHE_NAME)))); if ($worker_id >= $server->setting['worker_num']) { - $annotation->read(MODEL_PATH, 'App'); $annotation->runtime(APP_PATH, [CONTROLLER_PATH, TASK_PATH, LISTENER_PATH]); $this->onTask($server, $annotation); } else { - $annotation->read(directory('app'), 'App'); - $annotation->runtime(directory('app')); - + $annotation->runtime(CONTROLLER_PATH); + $annotation->runtime(directory('app'), [CONTROLLER_PATH]); $this->onWorker($server, $annotation); } } diff --git a/System/Runtime.php b/System/Runtime.php index dd304169..dfb37bc8 100644 --- a/System/Runtime.php +++ b/System/Runtime.php @@ -22,6 +22,9 @@ class Runtime extends Command public string $description = 'create app file cache'; + const CACHE_NAME = '.runtime.cache'; + + /** * @param Input $dtl * @throws Exception @@ -31,7 +34,7 @@ class Runtime extends Command // TODO: Implement onHandler() method. $annotation = Snowflake::app()->getAnnotation(); - $runtime = storage('runtime.php'); + $runtime = storage(static::CACHE_NAME); Snowflake::writeFile($runtime, serialize($annotation->getLoader())); }