Sourcing a file into a shell, such as bash
, requires that shell be running and it just reads in that file and interprets it. When you run php
from the shells command line it forks a separate process that inherits the environment. When that process ends it throws away the memory footprint of the executable including the environment.
As to getting PHP
to execute a script, it will do the same - create separatete process for bash
(for example) and get that process to read in the script, interpret it, follows its commands to the letter then when it comes to an end the process will terminate along with thenvironmentalal changes that it has made.
So a possible solution for this is to do the following.
- The PHP script needs to determine its location in the file system.
- The PHP script needs to determine if it is calling it self.
- If the script is NOT calling itself, run a bash script to set up the environment, add an extra environment variable to enable it to determine it not to go down this route again and execulte itselt. Perhaps use something like
popen
to fire into bash
the commands source
, export
, exec php
- If the scipt is calling itself, just execute
Seems a lot of hassle. Just write a script to set up the environment and then fire off PHP.