From cb23e7332baf9a8e6a1b065269baa4e51aadecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=9A=84=E5=A6=82=E6=9E=9C?= Date: Tue, 8 Dec 2020 16:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 56ece9f..22dc0ba 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,5 @@ # file-watcher -## 热重启 - -例如在`Easyswoole`开发模式中,我们希望当有代码变动的时候,实现Server重启,示例代码如下: - -```php -namespace EasySwoole\EasySwoole; - - -use EasySwoole\EasySwoole\AbstractInterface\Event; -use EasySwoole\EasySwoole\Swoole\EventRegister; -use EasySwoole\FileWatcher\FileWatcher; -use EasySwoole\FileWatcher\WatchRule; - -class EasySwooleEvent implements Event -{ - public static function initialize() - { - date_default_timezone_set('Asia/Shanghai'); - } - - public static function mainServerCreate(EventRegister $register) - { - $watcher = new FileWatcher(); - $rule = new WatchRule(EASYSWOOLE_ROOT."/App"); - $watcher->addRule($rule); - $watcher->setOnChange(function (){ - Logger::getInstance()->info('file change ,reload!!!'); - ServerManager::getInstance()->getSwooleServer()->reload(); - }); - $watcher->attachServer(ServerManager::getInstance()->getSwooleServer()); - } -} -``` -> 注意,reload仅仅针对Worker进程加载的代码有效 - ## 使用规则 ### WatchRule @@ -121,4 +86,39 @@ $fileWatcher->setOnChange(function (array $list, \EasySwoole\FileWatcher\WatchRu /**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/ /**@var \Swoole\Server $server **/ $fileWatcher->attachServer($server); -``` \ No newline at end of file +``` + +## EasySwoole中用于热重启 + +例如在`Easyswoole`开发模式中,我们希望当有代码变动的时候,实现Server重启,示例代码如下: + +```php +namespace EasySwoole\EasySwoole; + + +use EasySwoole\EasySwoole\AbstractInterface\Event; +use EasySwoole\EasySwoole\Swoole\EventRegister; +use EasySwoole\FileWatcher\FileWatcher; +use EasySwoole\FileWatcher\WatchRule; + +class EasySwooleEvent implements Event +{ + public static function initialize() + { + date_default_timezone_set('Asia/Shanghai'); + } + + public static function mainServerCreate(EventRegister $register) + { + $watcher = new FileWatcher(); + $rule = new WatchRule(EASYSWOOLE_ROOT."/App"); + $watcher->addRule($rule); + $watcher->setOnChange(function (){ + Logger::getInstance()->info('file change ,reload!!!'); + ServerManager::getInstance()->getSwooleServer()->reload(); + }); + $watcher->attachServer(ServerManager::getInstance()->getSwooleServer()); + } +} +``` +> 注意,reload仅仅针对Worker进程加载的代码有效