Skip to content
Advertisement

How do I find out the currently running PHP executable?

From inside a PHP program I want to know the location of the binary executing it. Perl has $^X for this purpose. Is there an equivalent in PHP?

This is so it can execute a child PHP process using itself (rather than hard code a path or assume “php” is correct).

UPDATE

  1. I’m using lighttpd + FastCGI, not Apache + mod_php. So yes, there is a PHP binary.
  2. eval/include is not a solution because I’m spawning a server which has to live on beyond the request.

Things I’ve tried and don’t work:

  • $_SERVER['_'] looks like what I want from the command line but its actually from an environment variable set by the shell of the last executed program. When run from a web server this is the web server binary.
  • which php will not work because the PHP binary is not guaranteed to be the same one as is in the web server’s PATH.

Thanks in advance.

Advertisement

Answer

The PHP_BINDIR constant gives you the directory where the php binary is

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement