feat: 本次提交更新内容如下
php有问题,覆盖下
This commit is contained in:
@@ -114,12 +114,13 @@ class Process
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param string $commandline 指令
|
||||
* @param string|null $cwd 工作目录
|
||||
* @param array|null $env 环境变量
|
||||
* @param string|null $input 输入
|
||||
* @param int|float|null $timeout 超时时间
|
||||
* @param array $options proc_open的选项
|
||||
* @access public
|
||||
* @param string $commandline 指令
|
||||
* @param string|null $cwd 工作目录
|
||||
* @param array|null $env 环境变量
|
||||
* @param string|null $input 输入
|
||||
* @param int|float|null $timeout 超时时间
|
||||
* @param array $options proc_open的选项
|
||||
* @throws \RuntimeException
|
||||
* @api
|
||||
*/
|
||||
@@ -132,7 +133,7 @@ class Process
|
||||
$this->commandline = $commandline;
|
||||
$this->cwd = $cwd;
|
||||
|
||||
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DS)) {
|
||||
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
|
||||
$this->cwd = getcwd();
|
||||
}
|
||||
if (null !== $env) {
|
||||
@@ -141,10 +142,10 @@ class Process
|
||||
|
||||
$this->input = $input;
|
||||
$this->setTimeout($timeout);
|
||||
$this->useFileHandles = '\\' === DS;
|
||||
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
|
||||
$this->pty = false;
|
||||
$this->enhanceWindowsCompatibility = true;
|
||||
$this->enhanceSigchildCompatibility = '\\' !== DS && $this->isSigchildEnabled();
|
||||
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
|
||||
$this->options = array_replace([
|
||||
'suppress_errors' => true,
|
||||
'binary_pipes' => true,
|
||||
@@ -163,7 +164,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 运行指令
|
||||
* @param callback|null $callback
|
||||
* @access public
|
||||
* @param callback|null $callback
|
||||
* @return int
|
||||
*/
|
||||
public function run($callback = null)
|
||||
@@ -175,7 +177,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 运行指令
|
||||
* @param callable|null $callback
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @return self
|
||||
* @throws \RuntimeException
|
||||
* @throws ProcessFailedException
|
||||
@@ -195,7 +198,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 启动进程并写到 STDIN 输入后返回。
|
||||
* @param callable|null $callback
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @throws \RuntimeException
|
||||
* @throws \RuntimeException
|
||||
* @throws \LogicException
|
||||
@@ -216,7 +220,7 @@ class Process
|
||||
|
||||
$commandline = $this->commandline;
|
||||
|
||||
if ('\\' === DS && $this->enhanceWindowsCompatibility) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
|
||||
$commandline = 'cmd /V:ON /E:ON /C "(' . $commandline . ')';
|
||||
foreach ($this->processPipes->getFiles() as $offset => $filename) {
|
||||
$commandline .= ' ' . $offset . '>' . Utils::escapeArgument($filename);
|
||||
@@ -245,7 +249,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 重启进程
|
||||
* @param callable|null $callback
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @return Process
|
||||
* @throws \RuntimeException
|
||||
* @throws \RuntimeException
|
||||
@@ -264,7 +269,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 等待要终止的进程
|
||||
* @param callable|null $callback
|
||||
* @access public
|
||||
* @param callable|null $callback
|
||||
* @return int
|
||||
*/
|
||||
public function wait($callback = null)
|
||||
@@ -278,8 +284,8 @@ class Process
|
||||
|
||||
do {
|
||||
$this->checkTimeout();
|
||||
$running = '\\' === DS ? $this->isRunning() : $this->processPipes->areOpen();
|
||||
$close = '\\' !== DS || !$running;
|
||||
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
|
||||
$close = '\\' !== DIRECTORY_SEPARATOR || !$running;
|
||||
$this->readPipes(true, $close);
|
||||
} while ($running);
|
||||
|
||||
@@ -296,6 +302,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取PID
|
||||
* @access public
|
||||
* @return int|null
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
@@ -312,7 +319,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 将一个 POSIX 信号发送到进程中
|
||||
* @param int $signal
|
||||
* @access public
|
||||
* @param int $signal
|
||||
* @return Process
|
||||
*/
|
||||
public function signal($signal)
|
||||
@@ -324,6 +332,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 禁用从底层过程获取输出和错误输出。
|
||||
* @access public
|
||||
* @return Process
|
||||
*/
|
||||
public function disableOutput()
|
||||
@@ -342,6 +351,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 开启从底层过程获取输出和错误输出。
|
||||
* @access public
|
||||
* @return Process
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
@@ -358,6 +368,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 输出是否禁用
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isOutputDisabled()
|
||||
@@ -367,9 +378,9 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取当前的输出管道
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws \LogicException
|
||||
* @throws \LogicException
|
||||
* @api
|
||||
*/
|
||||
public function getOutput()
|
||||
@@ -380,13 +391,14 @@ class Process
|
||||
|
||||
$this->requireProcessIsStarted(__FUNCTION__);
|
||||
|
||||
$this->readPipes(false, '\\' === DS ? !$this->processInformation['running'] : true);
|
||||
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
||||
|
||||
return $this->stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以增量方式返回的输出结果。
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getIncrementalOutput()
|
||||
@@ -408,6 +420,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 清空输出
|
||||
* @access public
|
||||
* @return Process
|
||||
*/
|
||||
public function clearOutput()
|
||||
@@ -420,6 +433,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 返回当前的错误输出的过程 (STDERR)。
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorOutput()
|
||||
@@ -430,13 +444,14 @@ class Process
|
||||
|
||||
$this->requireProcessIsStarted(__FUNCTION__);
|
||||
|
||||
$this->readPipes(false, '\\' === DS ? !$this->processInformation['running'] : true);
|
||||
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
||||
|
||||
return $this->stderr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以增量方式返回 errorOutput
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getIncrementalErrorOutput()
|
||||
@@ -458,6 +473,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 清空 errorOutput
|
||||
* @access public
|
||||
* @return Process
|
||||
*/
|
||||
public function clearErrorOutput()
|
||||
@@ -470,6 +486,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取退出码
|
||||
* @access public
|
||||
* @return null|int
|
||||
*/
|
||||
public function getExitCode()
|
||||
@@ -485,6 +502,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取退出文本
|
||||
* @access public
|
||||
* @return null|string
|
||||
*/
|
||||
public function getExitCodeText()
|
||||
@@ -498,6 +516,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查是否成功
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful()
|
||||
@@ -507,6 +526,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 是否未捕获的信号已被终止子进程
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBeenSignaled()
|
||||
@@ -524,6 +544,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 返回导致子进程终止其执行的数。
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getTermSignal()
|
||||
@@ -541,6 +562,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查子进程信号是否已停止
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBeenStopped()
|
||||
@@ -554,6 +576,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 返回导致子进程停止其执行的数。
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getStopSignal()
|
||||
@@ -567,6 +590,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查是否正在运行
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isRunning()
|
||||
@@ -582,6 +606,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查是否已开始
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarted()
|
||||
@@ -591,6 +616,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查是否已终止
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isTerminated()
|
||||
@@ -602,6 +628,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取当前的状态
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
@@ -613,11 +640,12 @@ class Process
|
||||
|
||||
/**
|
||||
* 终止进程
|
||||
* @access public
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
if ('\\' === DS && !$this->isSigchildEnabled()) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
|
||||
exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
|
||||
if ($exitCode > 0) {
|
||||
throw new \RuntimeException('Unable to kill the process');
|
||||
@@ -642,6 +670,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 添加一行输出
|
||||
* @access public
|
||||
* @param string $line
|
||||
*/
|
||||
public function addOutput($line)
|
||||
@@ -652,6 +681,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 添加一行错误输出
|
||||
* @access public
|
||||
* @param string $line
|
||||
*/
|
||||
public function addErrorOutput($line)
|
||||
@@ -662,6 +692,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取被执行的指令
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getCommandLine()
|
||||
@@ -671,6 +702,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置指令
|
||||
* @access public
|
||||
* @param string $commandline
|
||||
* @return self
|
||||
*/
|
||||
@@ -683,6 +715,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取超时时间
|
||||
* @access public
|
||||
* @return float|null
|
||||
*/
|
||||
public function getTimeout()
|
||||
@@ -692,6 +725,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取idle超时时间
|
||||
* @access public
|
||||
* @return float|null
|
||||
*/
|
||||
public function getIdleTimeout()
|
||||
@@ -701,7 +735,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置超时时间
|
||||
* @param int|float|null $timeout
|
||||
* @access public
|
||||
* @param int|float|null $timeout
|
||||
* @return self
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
@@ -713,7 +748,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置idle超时时间
|
||||
* @param int|float|null $timeout
|
||||
* @access public
|
||||
* @param int|float|null $timeout
|
||||
* @return self
|
||||
*/
|
||||
public function setIdleTimeout($timeout)
|
||||
@@ -729,12 +765,13 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置TTY
|
||||
* @param bool $tty
|
||||
* @access public
|
||||
* @param bool $tty
|
||||
* @return self
|
||||
*/
|
||||
public function setTty($tty)
|
||||
{
|
||||
if ('\\' === DS && $tty) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
|
||||
throw new \RuntimeException('TTY mode is not supported on Windows platform.');
|
||||
}
|
||||
if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
|
||||
@@ -748,6 +785,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 检查是否是tty模式
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isTty()
|
||||
@@ -757,7 +795,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置pty模式
|
||||
* @param bool $bool
|
||||
* @access public
|
||||
* @param bool $bool
|
||||
* @return self
|
||||
*/
|
||||
public function setPty($bool)
|
||||
@@ -769,6 +808,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 是否是pty模式
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isPty()
|
||||
@@ -778,6 +818,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取工作目录
|
||||
* @access public
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWorkingDirectory()
|
||||
@@ -791,7 +832,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置工作目录
|
||||
* @param string $cwd
|
||||
* @access public
|
||||
* @param string $cwd
|
||||
* @return self
|
||||
*/
|
||||
public function setWorkingDirectory($cwd)
|
||||
@@ -803,6 +845,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取环境变量
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getEnv()
|
||||
@@ -812,7 +855,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置环境变量
|
||||
* @param array $env
|
||||
* @access public
|
||||
* @param array $env
|
||||
* @return self
|
||||
*/
|
||||
public function setEnv(array $env)
|
||||
@@ -831,6 +875,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取输入
|
||||
* @access public
|
||||
* @return null|string
|
||||
*/
|
||||
public function getInput()
|
||||
@@ -840,7 +885,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置输入
|
||||
* @param mixed $input
|
||||
* @access public
|
||||
* @param mixed $input
|
||||
* @return self
|
||||
*/
|
||||
public function setInput($input)
|
||||
@@ -856,6 +902,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 获取proc_open的选项
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
@@ -865,7 +912,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置proc_open的选项
|
||||
* @param array $options
|
||||
* @access public
|
||||
* @param array $options
|
||||
* @return self
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
@@ -877,6 +925,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 是否兼容windows
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function getEnhanceWindowsCompatibility()
|
||||
@@ -886,7 +935,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 设置是否兼容windows
|
||||
* @param bool $enhance
|
||||
* @access public
|
||||
* @param bool $enhance
|
||||
* @return self
|
||||
*/
|
||||
public function setEnhanceWindowsCompatibility($enhance)
|
||||
@@ -898,6 +948,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 返回是否 sigchild 兼容模式激活
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function getEnhanceSigchildCompatibility()
|
||||
@@ -907,7 +958,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 激活 sigchild 兼容性模式。
|
||||
* @param bool $enhance
|
||||
* @access public
|
||||
* @param bool $enhance
|
||||
* @return self
|
||||
*/
|
||||
public function setEnhanceSigchildCompatibility($enhance)
|
||||
@@ -941,6 +993,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 是否支持pty
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPtySupported()
|
||||
@@ -951,7 +1004,7 @@ class Process
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ('\\' === DS) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
return $result = false;
|
||||
}
|
||||
|
||||
@@ -967,11 +1020,12 @@ class Process
|
||||
|
||||
/**
|
||||
* 创建所需的 proc_open 的描述符
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function getDescriptors()
|
||||
{
|
||||
if ('\\' === DS) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->processPipes = WindowsPipes::create($this, $this->input);
|
||||
} else {
|
||||
$this->processPipes = UnixPipes::create($this, $this->input);
|
||||
@@ -990,7 +1044,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 建立 wait () 使用的回调。
|
||||
* @param callable|null $callback
|
||||
* @access protected
|
||||
* @param callable|null $callback
|
||||
* @return callable
|
||||
*/
|
||||
protected function buildCallback($callback)
|
||||
@@ -1013,6 +1068,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @access protected
|
||||
* @param bool $blocking
|
||||
*/
|
||||
protected function updateStatus($blocking)
|
||||
@@ -1024,7 +1080,7 @@ class Process
|
||||
$this->processInformation = proc_get_status($this->process);
|
||||
$this->captureExitCode();
|
||||
|
||||
$this->readPipes($blocking, '\\' === DS ? !$this->processInformation['running'] : true);
|
||||
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
||||
|
||||
if (!$this->processInformation['running']) {
|
||||
$this->close();
|
||||
@@ -1033,6 +1089,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 是否开启 '--enable-sigchild'
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSigchildEnabled()
|
||||
@@ -1053,7 +1110,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 验证是否超时
|
||||
* @param int|float|null $timeout
|
||||
* @access private
|
||||
* @param int|float|null $timeout
|
||||
* @return float|null
|
||||
*/
|
||||
private function validateTimeout($timeout)
|
||||
@@ -1071,8 +1129,9 @@ class Process
|
||||
|
||||
/**
|
||||
* 读取pipes
|
||||
* @param bool $blocking
|
||||
* @param bool $close
|
||||
* @access private
|
||||
* @param bool $blocking
|
||||
* @param bool $close
|
||||
*/
|
||||
private function readPipes($blocking, $close)
|
||||
{
|
||||
@@ -1100,6 +1159,7 @@ class Process
|
||||
|
||||
/**
|
||||
* 关闭资源
|
||||
* @access private
|
||||
* @return int 退出码
|
||||
*/
|
||||
private function close()
|
||||
@@ -1146,8 +1206,9 @@ class Process
|
||||
|
||||
/**
|
||||
* 将一个 POSIX 信号发送到进程中。
|
||||
* @param int $signal
|
||||
* @param bool $throwException
|
||||
* @access private
|
||||
* @param int $signal
|
||||
* @param bool $throwException
|
||||
* @return bool
|
||||
*/
|
||||
private function doSignal($signal, $throwException)
|
||||
@@ -1183,7 +1244,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 确保进程已经开启
|
||||
* @param string $functionName
|
||||
* @access private
|
||||
* @param string $functionName
|
||||
*/
|
||||
private function requireProcessIsStarted($functionName)
|
||||
{
|
||||
@@ -1194,7 +1256,8 @@ class Process
|
||||
|
||||
/**
|
||||
* 确保进程已经终止
|
||||
* @param string $functionName
|
||||
* @access private
|
||||
* @param string $functionName
|
||||
*/
|
||||
private function requireProcessIsTerminated($functionName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user