I'm trying to set a variable that should be accessible from outside PHP. Ideally this should be a local variable, but environment variables are also welcome.
First, I've tried putenv()
, but this gives no result:
$ php -r "putenv('PHP_TEST=string');" ; echo $PHP_TEST
$
When i call getenv()
from the same script — it results in the right 'string' value.
Safe mode is off, but the manual says 'PHP_' prefix is vital with safe=on so I use it just in case :)
Then I try system()
or shell_exec()
:
$ php -r "shell_exec('PHP_TEST=string');" ; echo $PHP_TEST
$ php -r "shell_exec('export PHP_TEST=string');" ; echo $PHP_TEST
$
Is there a workaround? what might be the reason? I'm using Ubuntu Linux 9.10 "Karmic", but FreeBSD server gives the same result.