Last active
August 20, 2016 00:53
-
-
Save PeterJCLaw/23719e515c787e70b614f45392dc21aa to your computer and use it in GitHub Desktop.
Demo of issue with proc_open dropping hyphenated environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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