改进 命令处理为 pipe
This commit is contained in:
parent
81a8785213
commit
39fd536bae
@ -5,7 +5,6 @@
|
|||||||
use App\Support\Cluster;
|
use App\Support\Cluster;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Redis;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||||
|
|
||||||
@ -123,21 +122,7 @@ public function handle(): int
|
|||||||
$this->info('正在启动 Web。');
|
$this->info('正在启动 Web。');
|
||||||
|
|
||||||
$command = 'php artisan octane:start --host=0.0.0.0 --rpc-port=6001 --port=8000';
|
$command = 'php artisan octane:start --host=0.0.0.0 --rpc-port=6001 --port=8000';
|
||||||
// proc_open
|
$this->pipeCommand($command);
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 子进程
|
// 子进程
|
||||||
@ -180,7 +165,8 @@ private function dispatchEvent($event, $message = []): void
|
|||||||
'cluster.restart.web' => function () {
|
'cluster.restart.web' => function () {
|
||||||
$this->info('正在重启 Web。');
|
$this->info('正在重启 Web。');
|
||||||
|
|
||||||
exec('php artisan octane:reload');
|
$this->pipeCommand('php artisan octane:reload');
|
||||||
|
|
||||||
|
|
||||||
Cluster::publish('cluster.restarted.web');
|
Cluster::publish('cluster.restarted.web');
|
||||||
|
|
||||||
@ -189,7 +175,7 @@ private function dispatchEvent($event, $message = []): void
|
|||||||
'cluster.restart.all' => function () {
|
'cluster.restart.all' => function () {
|
||||||
$this->info('正在重启整个莱云。');
|
$this->info('正在重启整个莱云。');
|
||||||
|
|
||||||
exec('supervisorctl restart all');
|
$this->pipeCommand('supervisorctl restart all');
|
||||||
|
|
||||||
Cluster::publish('cluster.restarted.all');
|
Cluster::publish('cluster.restarted.all');
|
||||||
|
|
||||||
@ -226,4 +212,21 @@ private function getCpuUsage(): float
|
|||||||
$cpu = sys_getloadavg();
|
$cpu = sys_getloadavg();
|
||||||
return $cpu[0];
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user