[李景山php]每天TP5-20170120|thinkphp5-Process.php-2

/**
 * @var array
 */
public static $exitCodes = [// 異常退出 代碼
    0   => 'OK',// 正常退出
    1   => 'General error',// 一般性錯誤
    2   => 'Misuse of shell builtins', // 缺少腳本
    126 => 'Invoked command cannot execute',// 執行命令錯誤
    127 => 'Command not found',// 命令沒找到
    128 => 'Invalid exit argument',// 輸入 參數異常
    // signals
    129 => 'Hangup',// 上行
    130 => 'Interrupt',// 中斷
    131 => 'Quit and dump core',// 退出 並且 打印 內核
    132 => 'Illegal instruction',//
    133 => 'Trace/breakpoint trap',
    134 => 'Process aborted',
    135 => 'Bus error: "access to undefined portion of memory object"',
    136 => 'Floating point exception: "erroneous arithmetic operation"',
    137 => 'Kill (terminate immediately)',
    138 => 'User-defined 1',
    139 => 'Segmentation violation',
    140 => 'User-defined 2',
    141 => 'Write to pipe with no one reading',
    142 => 'Signal raised by alarm',
    143 => 'Termination (request to terminate)',
    // 144 - not defined
    145 => 'Child process terminated, stopped (or continued*)',
    146 => 'Continue if stopped',
    147 => 'Stop executing temporarily',
    148 => 'Terminal stop signal',
    149 => 'Background process attempting to read from tty ("in")',
    150 => 'Background process attempting to write to tty ("out")',
    151 => 'Urgent data available on socket',
    152 => 'CPU time limit exceeded',
    153 => 'File size limit exceeded',
    154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
    155 => 'Profiling timer expired',
    // 156 - not defined
    157 => 'Pollable event',
    // 158 - not defined
    159 => 'Bad syscall',
];

/**
 * 構造方法
 * @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
 */
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = [])
{// 命令 工作目錄 環境變量 輸入 超時時間 選項 數組
    if (!function_exists('proc_open')) {// 如果進程 處理函數 不存在 則 報錯
        throw new \RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
    }

    $this->commandline = $commandline;// 指令
    $this->cwd         = $cwd;// 目錄

    if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DS)) {//
        // 如果目錄爲空,並且 定義了 zend_thread_safe 線程安全 並且 不是 windos 下
        $this->cwd = getcwd();// 通過獲取 工作目錄的 方式 進行 獲取 數據
    }
    if (null !== $env) {// 如果環境變量 不爲空
        $this->setEnv($env);// 設置環境變量
    }

    $this->input = $input;// 輸入獲取
    $this->setTimeout($timeout);// 設置超時時間
    $this->useFileHandles               = '\\' === DS;// 是否使用文本處理
    $this->pty                          = false;// 狀態
    $this->enhanceWindowsCompatibility  = true;// 能夠執行窗口命令
    $this->enhanceSigchildCompatibility = '\\' !== DS && $this->isSigchildEnabled();// 能夠執行 子命令
    $this->options                      = array_replace([// 選項
        'suppress_errors' => true,
        'binary_pipes'    => true
    ], $options);
}// 構造函數 就是 進行了 各種 函數的初始化

public function __destruct()// 析構函數
{
    $this->stop();
}

public function __clone()// 複製函數
{
    $this->resetProcessData();
}

/**
 * 運行指令
 * @param callback|null $callback
 * @return int
 */
public function run($callback = null)// 運行 函數
{
    $this->start($callback);

    return $this->wait();
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章