Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo of issue with proc_open dropping hyphenated environment variables
<?php
putenv('INNER=aeiou');
putenv('INNER-VAR=aeiou');
#echo PHP_EOL, '-- REQUIRE_ONCE START --', PHP_EOL, PHP_EOL;
#require_once('proc_open_test_helper.php');
#echo PHP_EOL, '-- REQUIRE_ONCE END --', PHP_EOL, PHP_EOL;
echo PHP_EOL, '-- SUBPROCESS START --', PHP_EOL, PHP_EOL;
$descriptorspec = array(
0 => array('file', '/dev/null', 'r'),
1 => array('pipe', 'w'),
2 => array('file', '/dev/null', 'a')
);
$process = proc_open('php proc_open_test_helper.php', $descriptorspec, $pipes);
if (!is_resource($process)) {
die('Failed to create process!');
}
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
echo "command returned $return_value", PHP_EOL;
echo PHP_EOL, '-- SUBPROCESS END --', PHP_EOL, PHP_EOL;
<?php
echo 'A-B=', getenv('A-B'), PHP_EOL;
echo 'FOO=', getenv('FOO'), PHP_EOL;
echo 'getenv("INNER"): ', getenv("INNER"), PHP_EOL;
echo 'getenv("INNER-VAR"): ', getenv("INNER-VAR"), PHP_EOL;
echo 'done', PHP_EOL;
env 'A-B=ZZZ' 'FOO=BAR' php proc_open_test.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.