Skip to content

Commit

Permalink
优化执行命令的参数拼接
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Sep 30, 2021
1 parent 9d7475b commit fa1632f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/Server/Cli/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Imi\Cli\Annotation\Option;
use Imi\Cli\ArgType;
use Imi\Cli\Contract\BaseCommand;
use function Imi\ttyExec;
use Imi\Util\File;

/**
Expand All @@ -27,18 +28,10 @@ class Server extends BaseCommand
*/
public function start(string $host, int $port): void
{
$cmd = '"' . \PHP_BINARY . '" -S ' . $host . ':' . $port . ' -t "' . File::path(App::get(AppContexts::APP_PATH), 'public') . '"';
$descriptorspec = [
['pipe', 'r'], // 标准输入,子进程从此管道中读取数据
['pipe', 'w'], // 标准输出,子进程向此管道中写入数据
];
$p = proc_open(\Imi\cmd($cmd), $descriptorspec, $pipes, null, null, [
'bypass_shell' => true,
ttyExec([
\PHP_BINARY,
'-S', $host . ':' . $port,
'-t', File::path(App::get(AppContexts::APP_PATH), 'public'),
]);
while ($tmp = fgets($pipes[1]))
{
echo $tmp;
}
proc_close($p);
}
}

0 comments on commit fa1632f

Please sign in to comment.