how to discover PHP interpreter name in a script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Fulbright

    #1

    how to discover PHP interpreter name in a script

    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: http://us2.php.net/manual/en/ref.info.php
    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

  • petersprc

    #2
    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
    so:

    <?

    function getWinPhpPath()
    {
    $path = false;
    if (!($mgmt = new COM("winmgmts:" ))) {
    trigger_error(" Failed to create management object.",
    E_USER_ERROR);
    } else {
    $procs = $mgmt->ExecQuery("sel ect * from Win32_Process where " .
    "ProcessId = " . getmypid());
    if ($proc = $procs->Next()) {
    $path = $proc->ExecutablePath ;
    } else {
    trigger_error(" Failed to retrieve process information.",
    E_USER_ERROR);
    }
    }
    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('extens ion_dir');
    if ($extDir === false) {
    trigger_error(" No extension dir.", E_USER_ERROR);
    } else {
    $path = dirname($extDir ) . '/php.exe';
    if (file_exists($p ath)) {
    $ret = $path;
    }
    }
    return $ret;
    }

    ?>

    On Mar 21, 8:23 pm, "Dan Fulbright" <dfulbri...@gma il.comwrote:
    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:http://us2.php.net/manual/en/ref.info.php
    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

    Comment

    Working...