I’d like to do a similar thing than How to "fork" a video conversion process into background, in php? :
exec("/usr/bin/php ./foo.php > /dev/null 2>&1 &"); // executed in Apache
However, this will run on a variety of platforms : my machine, where php is compiled in ~/, windows, several prod servers…
Is there a way to programmatically get the “/usr/bin/php” part ?
Things I could think of :
- get the current pid, guess executable from it
- in C, the first argument is the path to the executable, maybe there is something similar
Easiest way is to simply make sure the
phpCLI binary is found in$PATHenvironment variable, and then just usephp /path/to/foo.php.On UNIX you can also use
/usr/bin/env phpwhich will execute the firstphpbinary found in$PATH. But that obviously won’t work in Windows.Lastly one obvious way is to have the location to
PHPas a configurable option, and use the user-specified path when appropriate.