qqq
This commit is contained in:
+10
-8
@@ -21,10 +21,13 @@ class HotReload extends BaseProcess
|
|||||||
*/
|
*/
|
||||||
private array $watchFiles = [];
|
private array $watchFiles = [];
|
||||||
|
|
||||||
|
|
||||||
|
private array $md5Map = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|string[]
|
* @var array|string[]
|
||||||
*/
|
*/
|
||||||
private array $dirs = [APP_PATH . 'app/', APP_PATH . 'config/', APP_PATH . 'routes/'];
|
private array $dirs = [APP_PATH . 'app', APP_PATH . 'routes'];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +92,7 @@ class HotReload extends BaseProcess
|
|||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->watch($init, $dir);
|
$this->watch($init, rtrim($dir,'/'));
|
||||||
}
|
}
|
||||||
Event::add($init, fn() => $this->check($init));
|
Event::add($init, fn() => $this->check($init));
|
||||||
Event::cycle(function () use ($init) {
|
Event::cycle(function () use ($init) {
|
||||||
@@ -203,8 +206,7 @@ class HotReload extends BaseProcess
|
|||||||
if (!($events = inotify_read($inotify))) {
|
if (!($events = inotify_read($inotify))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$isReloading = Context::get('isReloading', false);
|
if (Context::exists('isReloading')) {
|
||||||
if ($isReloading) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +226,7 @@ class HotReload extends BaseProcess
|
|||||||
if ($fileType !== '.php') {
|
if ($fileType !== '.php') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Context::get('swoole_timer_after') !== -1) {
|
if (Context::exists('swoole_timer_after')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$int = @swoole_timer_after(2000, fn() => $this->reload($inotify));
|
$int = @swoole_timer_after(2000, fn() => $this->reload($inotify));
|
||||||
@@ -238,15 +240,14 @@ class HotReload extends BaseProcess
|
|||||||
*/
|
*/
|
||||||
public function reload($inotify): void
|
public function reload($inotify): void
|
||||||
{
|
{
|
||||||
Context::set('isReloading', true);
|
|
||||||
$this->trigger_reload();
|
$this->trigger_reload();
|
||||||
|
|
||||||
$this->clearWatch($inotify);
|
$this->clearWatch($inotify);
|
||||||
foreach ($this->dirs as $root) {
|
foreach ($this->dirs as $root) {
|
||||||
$this->watch($inotify, $root);
|
$this->watch($inotify, $root);
|
||||||
}
|
}
|
||||||
Context::set('swoole_timer_after', -1);
|
Context::remove('swoole_timer_after');
|
||||||
Context::set('isReloading', false);
|
Context::remove('isReloading');
|
||||||
$this->md5Map = [];
|
$this->md5Map = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,6 +329,7 @@ class HotReload extends BaseProcess
|
|||||||
//递归目录
|
//递归目录
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
$this->watch($inotify, $path);
|
$this->watch($inotify, $path);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//检测文件类型
|
//检测文件类型
|
||||||
|
|||||||
Reference in New Issue
Block a user