How do I find out the currently running PHP executable?
Yeah, $_SERVER['_']
is what you're talking about, or as near as exists. The reason you're getting a Web server binary when it's run from the web is that /usr/bin/php
has nothing to do with the Web server's execution; what it's running is a separate SAPI. There's nothing from the web PHP instance to point to /usr/bin/php
because there's no reason for there to be.
In PHP5.4 you can use the PHP_BINARY constant, it won't work via mod_php or similar but will via CGI etc.
For earlier versions of PHP readlink('/proc/self/exe');
will probably be fine, again it won't work via mod_php.
The PHP_BINDIR constant gives you the directory where the php binary is
The PHP_BINDIR
constant is probably the easiest thing to use; the next best thing I could come up with is basically re-creating that bindir path from the extension_dir
configuration setting:
$phpbin = preg_replace("@/lib(64)?/.*$@", "/bin/php", ini_get("extension_dir"));
It has a regex in it, so it feels more like your native perl(!) but otherwise is not especially optimal.