Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Last active August 20, 2016 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterJCLaw/23719e515c787e70b614f45392dc21aa to your computer and use it in GitHub Desktop.
Save PeterJCLaw/23719e515c787e70b614f45392dc21aa to your computer and use it in GitHub Desktop.
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