/** * Tries to find the system's PHP executable and returns it. * * @return string */ public static function getExecutable() { if (is_null(self::$executable)) { if (getenv('PHP_PATH')) { self::$executable = getenv('PHP_PATH'); if (!is_executable(self::$executable)) { throw new Exception('The defined PHP_PATH environment variable is not a valid PHP executable.'); } } else { self::$executable = PHP_BINDIR . DIRECTORY_SEPARATOR . 'php'; } } if (!is_executable(self::$executable)) { $path = getenv('PATH') ? getenv('PATH') : getenv('Path'); $extensions = DIRECTORY_SEPARATOR == '\\' ? getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com') : array(''); foreach (array('php5', 'php') as $executable) { foreach ($extensions as $extension) { foreach (explode(PATH_SEPARATOR, $path) as $dir) { $file = $dir . DIRECTORY_SEPARATOR . $executable . $extension; if (is_executable($file)) { self::$executable = $file; break 3; } } } } if (!is_executable(self::$executable)) { throw new Exception("Unable to find PHP executable."); } } return self::$executable; }