PHP system call function does not properly export variables PHP system call function does not properly export variables bash bash

PHP system call function does not properly export variables


Turns out the problem wasn't the setting of the environment variable, but accessing the socket. Since apache is running through systemd, it has an isolated /tmp (see https://unix.stackexchange.com/questions/345122/why-php-can-not-see-tmp-files) that is not the same as the /tmp where I was putting the socket. Moving the location made everything work just fine!


Hm, this simple test case seems to work via apache + mod_php (7.0)

<?phpheader('content-type: text/plain; charset=utf-8');$out = [];exec('SOME_VAR=FOO && echo $SOME_VAR', $out);// works too: exec('export SOME_VAR=FOO && echo $SOME_VAR', $out);var_dump($out);

output:

array(1) {  [0]=>  string(3) "FOO"}

In your case this would be

<?phpheader('content-type: text/plain; charset=utf-8');$out = [];exec('TS_SOCKET=/tmp/reencode.socket && tsp', $out);// also try: exec('export TS_SOCKET=/tmp/reencode.socket && tsp', $out);var_dump($out);