On Linux $_SERVER["_"]
contains path to PHP interpreter executable (for example /usr/bin/php -r 'echo $_SERVER["_"];'
will print /usr/bin/php
). On Windows XP with PHP 5.3 $_SERVER["_"]
is NULL
.
That's nothing to do with PHP itself. It's shell that defines that environment variable. PHP just picks it up
For instance, see here:
The shell sets up some default shell variables; PS2 is one of them. Other useful shell variables that are set or used in the Korn shell are:
- _ (underscore) -- When an external command is executed by the shell, this is set in the environment of the new process to the path of the executed command. In interactive use, this parameter is also set in the parent shell to the last word of the previous command.
- ...
I think your best shot in Windows is to write an internal function. E.g.
PHP_FUNCTION(get_php_path)
{
char path[MAX_PATH];
int result;
if (zend_parse_parameters_none() == FAILURE)
return;
result = GetModuleFileNameA(NULL, path, MAX_PATH);
if (result == 0)
RETURN_FALSE;
if (result == MAX_PATH) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Path is too large");
RETURN_FALSE;
}
RETURN_STRINGL(path, result, 1);
}
Example:
>php -r "echo get_php_path()"; D:\Users\Cataphract\Documents\php-trunk\Debug_TS\php.exe
While not perfect, you could try this:
$_SERVER['phprc'] . 'php.exe'
which would give you something like
C:\Program Files\PHP\php.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With