This commit is contained in:
2021-03-05 16:36:18 +08:00
parent 41df099f4c
commit aa4127ed0e
4 changed files with 22 additions and 11 deletions
+4 -4
View File
@@ -33,12 +33,12 @@ class OnWorkerStart extends Callback
*/ */
public function onHandler(Server $server, int $worker_id): void public function onHandler(Server $server, int $worker_id): void
{ {
putenv('worker=' . $worker_id);
putenv('state=start'); putenv('state=start');
putenv('worker=' . $worker_id);
$start = microtime(true); if (env('debug') === 'true') {
annotation()->read(APP_PATH . 'app', 'App'); annotation()->read(APP_PATH . 'app', 'App');
$this->debug(sprintf('scan app dir use time %s', microtime(true) - $start)); }
if ($worker_id >= $server->setting['worker_num']) { if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id); $this->onTask($server, $worker_id);
+12 -3
View File
@@ -463,10 +463,15 @@ class Server extends HttpService
{ {
$event = Snowflake::app()->getEvent(); $event = Snowflake::app()->getEvent();
$event->on(Event::SERVER_WORKER_START, function () { $event->on(Event::SERVER_WORKER_START, function () {
$annotation = Snowflake::app()->getAttributes();
if (env('debug') !== 'true') {
return;
}
$router = Snowflake::app()->getRouter(); $router = Snowflake::app()->getRouter();
$router->loadRouterSetting();
annotation()->instanceDirectoryFiles(CONTROLLER_PATH); $annotation->instanceDirectoryFiles(CONTROLLER_PATH);
$router->loadRouterSetting();
}); });
} }
@@ -478,7 +483,11 @@ class Server extends HttpService
{ {
$event = Snowflake::app()->getEvent(); $event = Snowflake::app()->getEvent();
$event->on(Event::SERVER_WORKER_START, function () { $event->on(Event::SERVER_WORKER_START, function () {
annotation()->instanceDirectoryFiles(SOCKET_PATH); $annotation = Snowflake::app()->getAttributes();
if (env('debug') !== 'true') {
return;
}
$annotation->instanceDirectoryFiles(SOCKET_PATH);
}); });
} }
+4 -3
View File
@@ -109,9 +109,10 @@ class Application extends BaseApplication
{ {
try { try {
fire(Event::SERVER_BEFORE_START); fire(Event::SERVER_BEFORE_START);
if (env('debug') === 'false') {
$this->set('input', $argv); $annotation = Snowflake::app()->getAttributes();
$annotation->read(APP_PATH . 'app', 'App');
}
$manager = Snowflake::app()->get('console'); $manager = Snowflake::app()->get('console');
$manager->setParameters($argv); $manager->setParameters($argv);
$class = $manager->search(); $class = $manager->search();
+2 -1
View File
@@ -1,6 +1,7 @@
<?php <?php
defined('APP_PATH') or define('APP_PATH', __DIR__ . '/../../'); defined('APP_PATH') or define('APP_PATH', realpath(__DIR__ . '/../../'));
use Annotation\Annotation; use Annotation\Annotation;
use Annotation\Attribute; use Annotation\Attribute;