You are here

function automatic_updates_find_php in Automatic Updates 7

Find the PHP executable.

Credit to Symfony\Component\Process\PhpExecutableFinder.

Return value

string|bool Path to PHP executable or FALSE if not locatable.

1 call to automatic_updates_find_php()
automatic_updates_exec_command in ./automatic_updates.module
Helper method to execute exec command.

File

./automatic_updates.module, line 197
Contains automatic_updates.module.

Code

function automatic_updates_find_php() {
  $name = 'php';

  // HHVM support.
  if (\defined('HHVM_VERSION')) {
    return (getenv('PHP_BINARY') ?: PHP_BINARY) . $args;
  }

  // PHP_BINARY return the current sapi executable.
  if (PHP_BINARY && \in_array(\PHP_SAPI, [
    'cli',
    'cli-server',
    'phpdbg',
  ], TRUE)) {
    return PHP_BINARY;
  }
  if ($php = getenv('PHP_PATH')) {
    if (!@is_executable($php)) {
      return FALSE;
    }
    return $php;
  }
  if ($php = getenv('PHP_PEAR_PHP_BIN')) {
    if (@is_executable($php)) {
      return $php;
    }
  }
  if (@is_executable($php = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) {
    return $php;
  }
  $extraDirs = [
    PHP_BINDIR,
  ];
  if ('\\' === \DIRECTORY_SEPARATOR) {
    $extraDirs[] = 'C:\\xampp\\php\\';
  }
  if (ini_get('open_basedir')) {
    $searchPath = array_merge(explode(PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs);
    $dirs = [];
    foreach ($searchPath as $path) {

      // Silencing against https://bugs.php.net/69240
      if (@is_dir($path)) {
        $dirs[] = $path;
      }
      else {
        if (basename($path) == $name && @is_executable($path)) {
          return $path;
        }
      }
    }
  }
  else {
    $dirs = array_merge(explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), $extraDirs);
  }
  $suffixes = [
    '',
  ];
  if ('\\' === \DIRECTORY_SEPARATOR) {
    $pathExt = getenv('PATHEXT');
    $suffixes = array_merge($pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes);
  }
  foreach ($suffixes as $suffix) {
    foreach ($dirs as $dir) {
      if (@is_file($file = $dir . \DIRECTORY_SEPARATOR . $name . $suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
        return $file;
      }
    }
  }
  return FALSE;
}