I'd like to call system("foo")
in PHP but also specify environment variables that "foo" will have access to when it runs. This is under Linux.
Any simple trick for that?
I'd like to call system("foo")
in PHP but also specify environment variables that "foo" will have access to when it runs. This is under Linux.
Any simple trick for that?
Citations from: The PHP Manual, Function Reference, putenv
For example, if a particular system command required a special value
of the environment variable LD_LIBRARY_PATH to execute successfully,
then the following code might be used on a *NIX system:
<?php
$saved = getenv("LD_LIBRARY_PATH"); // save old value
$newld = "/extra/library/dir:/another/path/to/lib"; // extra paths to add
if ($saved) { $newld .= ":$saved"; } // append old paths if any
putenv("LD_LIBRARY_PATH=$newld"); // set new value
system("mycommand -with args"); // do system command;
// mycommand is loaded using
// libs in the new path list
putenv("LD_LIBRARY_PATH=$saved"); // restore old value
?>