how to discover PHP interpreter name in a script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
How can I find the name of the PHP interpreter (i.e., C:\PHP\php-
cgi.exe) from a PHP script? I looked through all the functions on the
PHP options & information page:
but couldn't find anything. I'm using PHP 4 as CGI in IIS on a Windows
2000 server.

Thanks in advance.

Dan Fulbright
Broken Arrow, Oklahoma, USA

Re: how to discover PHP interpreter name in a script

On Windows, you could use getmypid and the Windows Management
Interface COM object to get informatino about the current process like


function getWinPhpPath()
  $path = false;
  if (!($mgmt = new COM("winmgmts:"))) {
    trigger_error("Failed to create management object.",
  } else {
    $procs = $mgmt->ExecQuery("select * from Win32_Process where " .
      "ProcessId = " . getmypid());
    if ($proc = $procs->Next()) {
      $path = $proc->ExecutablePath;
    } else {
      trigger_error("Failed to retrieve process information.",
  return $path;

echo "The executable path is: \"" . getWinPhpPath() . "\".";


If it doesn't work, you could spawn a wsh script that does the same
thing, but get the path of the parent process.

As an alternative, you could try guessing the path based on the
extensions dir:


function guessPhpExe()
  $ret = false;
  $extDir = ini_get('extension_dir');
  if ($extDir === false) {
    trigger_error("No extension dir.", E_USER_ERROR);
  } else {
    $path = dirname($extDir) . '/php.exe';
    if (file_exists($path)) {
      $ret = $path;
  return $ret;


Quoted text here. Click to load it

Site Timeline