Skip to content

Commit

Permalink
fix: 修复初始化安装时清理缓存报错的问题
Browse files Browse the repository at this point in the history
修改aapanel 安装文档增加inotify 扩展说明
修改webman.php 自动检测是否安装inotify扩展,如果安装则自动拉取热重载监控
  • Loading branch information
xboard committed May 28, 2024
1 parent fd52795 commit 7246eb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/XboardInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function handle()
$this->saveToEnv($envConfig);

$this->call('config:cache');
$this->call('cache:clear');
\Artisan::call('cache:clear');
$this->info('正在导入数据库请稍等...');
\Artisan::call("migrate", ['--force' => true]);
$this->info(\Artisan::output());
Expand Down
2 changes: 1 addition & 1 deletion docs/aapanel安装指南.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ URL=https://www.aapanel.com/script/install_6.0_en.sh && if [ -f /usr/bin/curl ];
- swoole4
- readline
- event
- inotify
- inotify (可选,热重载依赖)

4. 解除被禁止函数
> aaPanel 面板 > App Store > 找到PHP 8.1点击Setting > Disabled functions 将以下函数从列表中删除
Expand Down
57 changes: 30 additions & 27 deletions webman.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,40 @@
}
};

$worker = new Worker();
$worker->name = 'FileMonitor';
$worker->reloadable = false;
$monitor_dirs = ['app', 'bootstrap', 'config', 'resources', 'routes', 'public', '.env'];
$monitor_files = array();
if (extension_loaded('inotify')) {
$worker = new Worker();
$worker->name = 'FileMonitor';
$worker->reloadable = false;
$monitor_dirs = ['app', 'bootstrap', 'config', 'resources', 'routes', 'public', '.env'];
$monitor_files = array();

// 进程启动后创建inotify监控句柄
$worker->onWorkerStart = function ($worker) {
if (!extension_loaded('inotify')) {
echo "FileMonitor : Please install inotify extension.\n";
return;
}
global $monitor_dirs, $monitor_files;
$worker->inotifyFd = inotify_init();
stream_set_blocking($worker->inotifyFd, 0);
// 进程启动后创建inotify监控句柄
$worker->onWorkerStart = function ($worker) {
if (!extension_loaded('inotify')) {
echo "FileMonitor : Please install inotify extension.\n";
return;
}
global $monitor_dirs, $monitor_files;
$worker->inotifyFd = inotify_init();
stream_set_blocking($worker->inotifyFd, 0);

foreach ($monitor_dirs as $monitor_dir) {
$monitor_realpath = realpath(__DIR__ . "/{$monitor_dir}");
addInofity($monitor_realpath, $worker->inotifyFd);
if (is_file($monitor_realpath))
continue;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($monitor_realpath, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
if ($file->isDir()) {
$realpath = realpath($file);
addInofity($realpath, $worker->inotifyFd);
foreach ($monitor_dirs as $monitor_dir) {
$monitor_realpath = realpath(__DIR__ . "/{$monitor_dir}");
addInofity($monitor_realpath, $worker->inotifyFd);
if (is_file($monitor_realpath))
continue;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($monitor_realpath, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
if ($file->isDir()) {
$realpath = realpath($file);
addInofity($realpath, $worker->inotifyFd);
}
}
}
}
Worker::$globalEvent->add($worker->inotifyFd, EventInterface::EV_READ, 'check_files_change');
};
Worker::$globalEvent->add($worker->inotifyFd, EventInterface::EV_READ, 'check_files_change');
};
}

function addInofity(string $realpath, $fd)
{
global $monitor_files;
Expand Down

0 comments on commit 7246eb6

Please sign in to comment.