Menu

#162 Improve getPHPExecutableFromPath()

0.9
closed
nobody
None
1
2014-12-29
2014-01-16
No

On Linux and certain install, env variable PATH is not available (nginx+fpm), so PHP executable is never found.
We could rewrite function getPHPExecutableFromPath() in functions/functions-common.php to check additional paths :

<?php
function getPHPExecutableFromPath()
{
    $paths = explode(PATH_SEPARATOR, getenv('PATH'));
    foreach ($paths as $path) {
        // we need this for XAMPP (Windows)
        if (strstr($path, 'php.exe') && isset($_SERVER["WINDIR"]) && file_exists($path) && is_file($path)) {
            return $path;
        }
        else {
            $php_executable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : "");
            if (file_exists($php_executable) && is_file($php_executable)) {
                return $php_executable;
            }
        }
    }
    // Nothing found yet ? Linux ?
    if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
        $paths = array('/bin', '/usr/bin', '/usr/local/bin');
        foreach ($paths as $path) {
            if (file_exists($path.'/php'))
                return $path.'/php';
        }
    }
    return FALSE; // not found
}

Discussion

  • Miha Petkovsek

    Miha Petkovsek - 2014-01-16

    Hi, I have change lots of this in latest dev release, returning also the error code if ping fails.

    For above it seems there is a PHP_BINDIR constant that can be used instead of this for linux:

    $php_executable = PHP_BINDIR."/php";
    if (file_exists($php_executable) && is_file($php_executable)) {
        return $php_executable;
    }
    
     
  • Miha Petkovsek

    Miha Petkovsek - 2014-02-21
    • status: open --> closed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB