worker_pid, $worker_id >= $server->setting['worker_num'] ? 'task' : 'worker'); $annotation = Snowflake::app()->getAnnotation(); /** @var Loader $runtime */ $runtime = unserialize(file_get_contents(storage('runtime.php'))); $annotation->setLoader($runtime); if ($worker_id >= $server->setting['worker_num']) { $annotation->instanceDirectoryFiles(MODEL_PATH); $this->onTask($server, $worker_id); } else { $start = microtime(true); $annotation->instanceDirectoryFiles($workerDir = realpath(APP_PATH . 'app/Http')); $this->error('use time ' . (microtime(true) - $start)); Coroutine\go(function () use ($annotation, $workerDir) { $annotation->instanceDirectoryFiles(APP_PATH, $workerDir); }); $this->onWorker($server, $worker_id); } } /** * @param Server $server * @param int $worker_id * @throws Exception */ public function onTask(Server $server, int $worker_id) { putenv('environmental=' . Snowflake::TASK); Snowflake::setTaskId($server->worker_pid); fire(Event::SERVER_TASK_START); } /** * @param Server $server * @param int $worker_id * @throws Exception */ public function onWorker(Server $server, int $worker_id) { Snowflake::setWorkerId($server->worker_pid); putenv('environmental=' . Snowflake::WORKER); try { fire(Event::SERVER_WORKER_START, [$worker_id]); } catch (\Throwable $exception) { $this->addError($exception, 'throwable'); write($exception->getMessage(), 'worker'); } } }