Calvin1602
Calvin1602

Reputation: 9547

Programmatically get path to php

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 :

Upvotes: 1

Views: 1064

Answers (1)

reko_t
reko_t

Reputation: 56430

Easiest way is to simply make sure the php CLI binary is found in $PATH environment variable, and then just use php /path/to/foo.php.

On UNIX you can also use /usr/bin/env php which will execute the first php binary found in $PATH. But that obviously won't work in Windows.

Lastly one obvious way is to have the location to PHP as a configurable option, and use the user-specified path when appropriate.

Upvotes: 2

Related Questions