diff --git a/app/Console/Commands/Cluster/Work.php b/app/Console/Commands/Cluster/Work.php index 621e6f0..573a5ff 100644 --- a/app/Console/Commands/Cluster/Work.php +++ b/app/Console/Commands/Cluster/Work.php @@ -5,7 +5,6 @@ use App\Support\Cluster; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Redis; use Illuminate\Support\Str; use Symfony\Component\Console\Command\Command as CommandAlias; @@ -123,21 +122,7 @@ public function handle(): int $this->info('正在启动 Web。'); $command = 'php artisan octane:start --host=0.0.0.0 --rpc-port=6001 --port=8000'; - // proc_open - $descriptor_spec = [ - 0 => ['pipe', 'r'], - 1 => ['pipe', 'w'], - 2 => ['pipe', 'w'], - ]; - - $process = proc_open($command, $descriptor_spec, $pipes); - - if (is_resource($process)) { - while ($s = fgets($pipes[1])) { - echo $s; - } - } - + $this->pipeCommand($command); } else { // 子进程 @@ -180,7 +165,8 @@ private function dispatchEvent($event, $message = []): void 'cluster.restart.web' => function () { $this->info('正在重启 Web。'); - exec('php artisan octane:reload'); + $this->pipeCommand('php artisan octane:reload'); + Cluster::publish('cluster.restarted.web'); @@ -189,7 +175,7 @@ private function dispatchEvent($event, $message = []): void 'cluster.restart.all' => function () { $this->info('正在重启整个莱云。'); - exec('supervisorctl restart all'); + $this->pipeCommand('supervisorctl restart all'); Cluster::publish('cluster.restarted.all'); @@ -226,4 +212,21 @@ private function getCpuUsage(): float $cpu = sys_getloadavg(); return $cpu[0]; } + + private function pipeCommand($command): void + { + $descriptor_spec = [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; + + $process = proc_open($command, $descriptor_spec, $pipes); + + if (is_resource($process)) { + while ($s = fgets($pipes[1])) { + echo $s; + } + } + } }