[李景山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();
}


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