From 1123de6ce9f2b111b6b9990c403d23b3c13bdbb4 Mon Sep 17 00:00:00 2001 From: huanglonghui Date: Fri, 12 Jan 2024 16:22:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=90=9C=E7=B4=A2=E7=B4=A2=E5=BC=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasySwooleEvent.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/EasySwooleEvent.php b/EasySwooleEvent.php index 654139d..bf1dd8c 100644 --- a/EasySwooleEvent.php +++ b/EasySwooleEvent.php @@ -46,6 +46,29 @@ public static function mainServerCreate(EventRegister $register) $en->getTemplate()->setPageNotFoundTpl('404.tpl'); DocContainer::getInstance()->add($en); - Manager::getInstance()->addProcess(new TickProcess()); + // Manager::getInstance()->addProcess(new TickProcess()); + self::initSearch(); } -} \ No newline at end of file + + private static function initSearch() + { + $scheduler = new \Swoole\Coroutine\Scheduler(); + $scheduler->add(function() { + go(function () { + // 写入搜索内容json + $list = Config::getInstance()->getConf("DOC.ALLOW_LANGUAGE"); + try { + foreach ($list as $dir => $value) { + $json = DocSearchParser::parserDoc2JsonUrlMap(EASYSWOOLE_ROOT, "{$dir}"); + file_put_contents(EASYSWOOLE_ROOT . "/Static/keyword{$dir}.json", json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + } + } catch (\Throwable $throwable) { + \EasySwoole\EasySwoole\Trigger::getInstance()->throwable($throwable); + } + }); + }); + $scheduler->start(); + // 清除全部定时器 + \Swoole\Timer::clearAll(); + } +}