From 429bc2f576a17b5fa9a6af768895d5737d177b01 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Wed, 22 Oct 2025 18:53:22 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A8=8B=E5=BA=8F=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E3=80=91=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminapi/controller/PublicController.php | 47 ++++++++++++++++--- crmeb/app/adminapi/route/route.php | 2 +- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/crmeb/app/adminapi/controller/PublicController.php b/crmeb/app/adminapi/controller/PublicController.php index 61c7c38ad..5615867e2 100644 --- a/crmeb/app/adminapi/controller/PublicController.php +++ b/crmeb/app/adminapi/controller/PublicController.php @@ -127,18 +127,51 @@ class PublicController ]; if (function_exists('exec')) { $workermanOutput = $timerOutput = $queueOutput = []; - exec("ps aux | grep 'php think workerman' | grep -v grep", $workermanOutput); - exec("ps aux | grep 'php think timer' | grep -v grep", $timerOutput); - exec("ps aux | grep 'php think queue' | grep -v grep", $queueOutput); + // exec("ps aux | grep 'php think workerman' | grep -v grep", $workermanOutput); + $targetPort = config('workerman.chat.port'); + $thinkPath = root_path(); // think 文件的绝对路径 + $checkService = function($service) { + if($service === 'queue'){ + $command = 'queue:listen'; + // 执行 ps 命令查找队列进程 + exec("ps aux | grep '{$command}' | grep -v grep", $output); + + // 若输出不为空,说明进程存在 + return !empty($output); + } else { + $pidFile = root_path('runtime') . $service . '.pid'; + // 优先检查PID文件 + if (!file_exists($pidFile)) { + return false; + } + + // 如果PID文件存在,尝试获取进程状态 + $pid = trim(file_get_contents($pidFile)); + if ($pid && is_numeric($pid)) { + if (function_exists('posix_kill') && posix_kill($pid, 0)) { + return true; + } + // 备用检查方法 + if (function_exists('exec')) { + $output = []; + exec("ps -ef | grep " . escapeshellarg($pid) . " | grep -v grep", $output); + // 判断是否有非 grep 进程的输出 + return !empty($output); + } + } + } + }; + $info['process'] = [ - ['name' => '长链接', 'require' => '开启', 'value' => count($workermanOutput) > 0], - ['name' => '定时任务', 'require' => '开启', 'value' => count($timerOutput) > 0], - ['name' => '消息队列', 'require' => '开启', 'value' => count($queueOutput) > 0], + ['name' => '长链接', 'require' => '开启', 'value' => $checkService('workerman')], + ['name' => '定时任务', 'require' => '开启', 'value' => $checkService('timer')], + ['name' => '消息队列', 'require' => '开启', 'value' => $checkService('queue')], ]; + } else { $info['process'] = [ ['name' => '长链接', 'require' => '开启', 'value' => file_exists(root_path('runtime') . 'workerman.pid')], - ['name' => '定时任务', 'require' => '开启', 'value' => file_exists(root_path('runtime') . '.timer')], + ['name' => '定时任务', 'require' => '开启', 'value' => file_exists(root_path('runtime') . 'timer.pid')], ['name' => '消息队列', 'require' => '开启', 'value' => file_exists(root_path('runtime') . '.queue')], ]; } diff --git a/crmeb/app/adminapi/route/route.php b/crmeb/app/adminapi/route/route.php index e189b06a4..0b5bcb184 100644 --- a/crmeb/app/adminapi/route/route.php +++ b/crmeb/app/adminapi/route/route.php @@ -53,7 +53,7 @@ Route::group(function () { Route::get('download/[:key]', 'PublicController/download')->option(['real_name' => '下载文件']); })->middleware([ AllowOriginMiddleware::class, -// \app\adminapi\middleware\AdminAuthTokenMiddleware::class + \app\adminapi\middleware\AdminAuthTokenMiddleware::class ])->option(['mark' => 'system', 'mark_name' => '系统相关']); /**