Constructor.
@api
string $commandline The command line to run:
string $cwd The working directory:
array $env The environment variables or null to inherit:
string $stdin The STDIN content:
integer $timeout The timeout in seconds:
array $options An array of options for proc_open:
RuntimeException When proc_open is not installed
public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array()) {
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;
// on windows, if the cwd changed via chdir(), proc_open defaults to the dir where php was started
// on gnu/linux, PHP builds with --enable-maintainer-zts are also affected
// @see : https://bugs.php.net/bug.php?id=51800
// @see : https://bugs.php.net/bug.php?id=50524
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
$this->cwd = getcwd();
}
if (null !== $env) {
$this->env = array();
foreach ($env as $key => $value) {
$this->env[(string) $key] = (string) $value;
}
}
else {
$this->env = null;
}
$this->stdin = $stdin;
$this
->setTimeout($timeout);
$this->enhanceWindowsCompatibility = true;
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this
->isSigchildEnabled();
$this->options = array_replace(array(
'suppress_errors' => true,
'binary_pipes' => true,
), $options);
}