From 340b082ee80461a01657b46c022b917b1e772575 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 8 Feb 2023 20:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20IP=20=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Cluster/Work.php | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/Cluster/Work.php b/app/Console/Commands/Cluster/Work.php index 370e582..1eeaf29 100644 --- a/app/Console/Commands/Cluster/Work.php +++ b/app/Console/Commands/Cluster/Work.php @@ -32,7 +32,7 @@ class Work extends Command public function handle(): int { // 检测目录下是否有 rr - if (! file_exists(base_path('rr'))) { + if (!file_exists(base_path('rr'))) { $this->warn('未找到 rr 文件,将自动下载。'); // 获取操作系统是 darwin 还是 linux @@ -70,16 +70,27 @@ public function handle(): int // 关闭 Octane Artisan::call('octane:stop'); - if (! config('settings.node.ip')) { + // 刷新配置缓存 + $this->info('正在刷新配置缓存。'); + Artisan::call('config:cache'); + Artisan::call('route:cache'); + + $node_ip = config('settings.node.ip'); + + if (!$node_ip) { $this->error('请先配置节点 IP。'); return CommandAlias::FAILURE; } - // 刷新配置缓存 - $this->info('正在刷新配置缓存。'); - Artisan::call('config:cache'); - Artisan::call('route:cache'); + // 获取端口 + $node_ips = explode(':', $node_ip); + $node_host = $node_ips[0]; + if (count($node_ips) === 1) { + $node_port = 8000; + } else { + $node_port = $node_ips[1]; + } // redis 创建一个 hash $this->info('正在注册节点。'); @@ -94,18 +105,18 @@ public function handle(): int $this->error('无法创建子进程。'); return CommandAlias::FAILURE; - } elseif ($pid === 0) { + } else if ($pid === 0) { // 再打开一个,负责 octane $pid = pcntl_fork(); if ($pid === -1) { $this->error('无法创建子进程。'); return CommandAlias::FAILURE; - } elseif ($pid === 0) { + } else if ($pid === 0) { // 子进程 $this->info('正在启动 Web。'); - $command = 'php artisan octane:start --host=0.0.0.0 --rpc-port=6001 --port=8000'; + $command = "php artisan octane:start --host=$node_host --port=$node_port"; $this->pipeCommand($command); } else { $this->report();