From 66543b82748bba438385d098b482cb8026d3b4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 2 Mar 2021 13:49:06 +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 --- System/Application.php | 19 +++++++++++-------- System/Error/Logger.php | 6 +++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/System/Application.php b/System/Application.php index 0f1f076d..a5dc2a57 100644 --- a/System/Application.php +++ b/System/Application.php @@ -25,6 +25,7 @@ use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindPropertyException; use stdClass; use Swoole\Timer; +use function Co\run; /** * Class Init @@ -98,10 +99,10 @@ class Application extends BaseApplication /** * @param Input $argv - * @return bool|string + * @return void * @throws Exception */ - public function start(Input $argv): bool|string + public function start(Input $argv): void { try { ini_set('opcache.enable', '1'); @@ -111,14 +112,16 @@ class Application extends BaseApplication fire(Event::SERVER_BEFORE_START); - $this->set('input', $argv); + run(function () use ($argv) { + $this->set('input', $argv); - $manager = Snowflake::app()->get('console'); - $manager->setParameters($argv); - $class = $manager->search(); - return response()->send($manager->execCommand($class)); + $manager = Snowflake::app()->get('console'); + $manager->setParameters($argv); + $class = $manager->search(); + response()->send($manager->execCommand($class)); + }); } catch (\Throwable $exception) { - return response()->send(implode("\n", [ + response()->send(implode("\n", [ 'Msg: ' . $exception->getMessage(), 'Line: ' . $exception->getLine(), 'File: ' . $exception->getFile() diff --git a/System/Error/Logger.php b/System/Error/Logger.php index 469f91b6..01887df9 100644 --- a/System/Error/Logger.php +++ b/System/Error/Logger.php @@ -167,7 +167,11 @@ class Logger extends Component $files = glob(storage(null, $dirName) . '/*'); if (count($files) >= 15) { - Coroutine\System::exec('find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;'); + $command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;'; + if (Context::inCoroutine()) + Coroutine\System::exec($command); + else + exec($command); } }