Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Created August 18, 2012 13:23
Show Gist options
  • Save yuya-takeyama/3386850 to your computer and use it in GitHub Desktop.
Save yuya-takeyama/3386850 to your computer and use it in GitHub Desktop.
proc_open()'s $env argument
<?php
$fdSpecs = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$process = proc_open('php -r "var_dump(\$_ENV);"', $fdSpecs, $pipes, getcwd());
echo 'Without $env argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(\$_ENV);"', $fdSpecs, $pipes, getcwd(), NULL);
echo 'With NULL as $env argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(\$_ENV);"', $fdSpecs, $pipes, getcwd(), $_ENV);
echo 'With $_ENV as $env argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(\$_ENV);"', $fdSpecs, $pipes, getcwd(), array('foo' => 'bar'));
echo 'With additional $env argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
$ php proc_open_env.php
Without $env argument:
array(0) {
}
With NULL as $env argument:
array(0) {
}
With $_ENV as $env argument:
array(4) {
["PWD"]=>
string(29) "/Users/yuya/dev/php/proc_open"
["SHLVL"]=>
string(1) "1"
["_"]=>
string(12) "/usr/bin/php"
["__CF_USER_TEXT_ENCODING"]=>
string(10) "0x1F5:1:14"
}
With additional $env argument:
array(5) {
["PWD"]=>
string(29) "/Users/yuya/dev/php/proc_open"
["foo"]=>
string(3) "bar"
["SHLVL"]=>
string(1) "1"
["_"]=>
string(12) "/usr/bin/php"
["__CF_USER_TEXT_ENCODING"]=>
string(10) "0x1F5:1:14"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment