[李景山php]每天TP5-20170124|thinkphp5-Process.php-6

來源:互聯網
上載者:User

標籤:thinkphp5

/** * 返回導致子進程終止其執行的數。 * @return int */public function getTermSignal(){// 返回 子進程 終止其執行的數    $this->requireProcessIsTerminated(__FUNCTION__);// 確認 進程 函數 已經終止,否則 拋出異常    if ($this->isSigchildEnabled()) {// 確認是否 子進程        throw new \RuntimeException(‘This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.‘);    }    $this->updateStatus(false);// 阻塞 非阻塞 串連池 串連等待    return $this->processInformation[‘termsig‘];// 返回 終止 異常資料}/** * 檢查子進程訊號是否已停止 * @return bool */public function hasBeenStopped(){    $this->requireProcessIsTerminated(__FUNCTION__);// 如果停止通過    $this->updateStatus(false);// 狀態 檢查 通過    return $this->processInformation[‘stopped‘];// 進程停止訊息}/** * 返回導致子進程停止其執行的數。 * @return int */public function getStopSignal(){    $this->requireProcessIsTerminated(__FUNCTION__);    $this->updateStatus(false);    return $this->processInformation[‘stopsig‘];}// 停止的 情況/** * 檢查是否正在運行 * @return bool */public function isRunning(){    if (self::STATUS_STARTED !== $this->status) {        return false;    }// 是否跑起來了    $this->updateStatus(false);// 檢測是否是關閉狀態    return $this->processInformation[‘running‘];// 返回提示句}/** * 檢查是否已開始 * @return bool */public function isStarted(){    return $this->status != self::STATUS_READY;// 直接根據 啟動標誌位進行 返回檢測}/** * 檢查是否已終止 * @return bool */public function isTerminated(){    $this->updateStatus(false);// 如果沒有關閉    return $this->status == self::STATUS_TERMINATED;// 進行 終止 檢測}/** * 擷取當前的狀態 * @return string */public function getStatus(){    $this->updateStatus(false);// 擷取目前狀態    return $this->status;// 返回目前狀態資訊}/** * 終止進程 */public function stop(){// 終止進程    if ($this->isRunning()) {// 是否運行        if (‘\\‘ === DS && !$this->isSigchildEnabled()) {            exec(sprintf(‘taskkill /F /T /PID %d 2>&1‘, $this->getPid()), $output, $exitCode);// 返回 linux 命令            if ($exitCode > 0) {// 如果執行狀態                throw new \RuntimeException(‘Unable to kill the process‘);// 異常情況            }        } else {            $pids = preg_split(‘/\s+/‘, `ps -o pid --no-heading --ppid {$this->getPid()}`);// 產看 pid 資訊            foreach ($pids as $pid) {// 迴圈遍曆                if (is_numeric($pid)) {// 數字進程                    posix_kill($pid, 9); // 殺死進程                }            }        }    }    $this->updateStatus(false);// 更新狀態    if ($this->processInformation[‘running‘]) {// 如果還在運行中        $this->close();// 關閉    }    return $this->exitcode;// 返回結束代碼}/** * 添加一行輸出 * @param string $line */public function addOutput($line){    $this->lastOutputTime = microtime(true);    $this->stdout .= $line;}// 添加輸出資訊 並且 更新最後的輸出時間/** * 添加一行錯誤輸出 * @param string $line */public function addErrorOutput($line){    $this->lastOutputTime = microtime(true);    $this->stderr .= $line;// 行資訊}// 添加一行錯誤輸出/** * 擷取被執行的指令 * @return string */public function getCommandLine(){    return $this->commandline;}// 擷取執行的指令/** * 設定指令 * @param string $commandline * @return self */public function setCommandLine($commandline){    $this->commandline = $commandline;    return $this;}// 設定指令/** * 擷取逾時時間 * @return float|null */public function getTimeout(){    return $this->timeout;}// 擷取逾時 時間/** * 擷取idle逾時時間 * @return float|null */public function getIdleTimeout(){    return $this->idleTimeout;}// 擷取 idle 逾時時間/** * 設定逾時時間 * @param int|float|null $timeout * @return self */public function setTimeout($timeout){    $this->timeout = $this->validateTimeout($timeout);    return $this;}// 設定 逾時 時間/** * 設定idle逾時時間 * @param int|float|null $timeout * @return self */public function setIdleTimeout($timeout){    if (null !== $timeout && $this->outputDisabled) {        throw new \LogicException(‘Idle timeout can not be set while the output is disabled.‘);    }    $this->idleTimeout = $this->validateTimeout($timeout);    return $this;}// 設定 idle 逾時 時間/** * 設定TTY * @param bool $tty * @return self */public function setTty($tty){    if (‘\\‘ === DS && $tty) {// 如果是 \\ 並且 需要設定 tty 這樣的話,證明在 window平台下        throw new \RuntimeException(‘TTY mode is not supported on Windows platform.‘);    }    if ($tty && (!file_exists(‘/dev/tty‘) || !is_readable(‘/dev/tty‘))) {// tty 必須可以讀取        throw new \RuntimeException(‘TTY mode requires /dev/tty to be readable.‘);    }    $this->tty = (bool)$tty;// 把當前的 tty 進行 資料類型強制轉化    return $this;// 返回當前類}/** * 檢查是否是tty模式 * @return bool */public function isTty()// 是否 tty 模式{    return $this->tty;}/** * 設定pty模式 * @param bool $bool * @return self */public function setPty($bool)// 設定 pty 模式{    $this->pty = (bool)$bool;    return $this;}/** * 是否是pty模式 * @return bool */public function isPty()// 是否 pty 模式{    return $this->pty;}/** * 擷取工作目錄 * @return string|null */public function getWorkingDirectory()// 擷取當前工作目錄, 讓我想起來了 linux pwd 命令{    if (null === $this->cwd) {        return getcwd() ?: null;    }    return $this->cwd;}/** * 設定工作目錄 * @param string $cwd * @return self */public function setWorkingDirectory($cwd)// 設定目錄{    $this->cwd = $cwd;    return $this;}/** * 擷取環境變數 * @return array */public function getEnv()// 擷取環境變數{    return $this->env;}/** * 設定環境變數 * @param array $env * @return self */public function setEnv(array $env)// 設定環境變數{    $env = array_filter($env, function ($value) {        return !is_array($value);    });    $this->env = [];    foreach ($env as $key => $value) {        $this->env[(binary)$key] = (binary)$value;    }    return $this;}// 過濾參數 並且 設定 資料


本文出自 “專註php 群號:414194301” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1886394

[李景山php]每天TP5-20170124|thinkphp5-Process.php-6

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.