/**
  * Finds The PHP executable.
  *
  * @param bool $includeArgs Whether or not include command arguments
  *
  * @return string|false The PHP executable path or false if it cannot be found
  */
 public function find($includeArgs = true)
 {
     // HHVM support
     if (defined('HHVM_VERSION')) {
         return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY) . ($includeArgs ? ' ' . implode(' ', $this->findArguments()) : '');
     }
     // PHP_BINARY return the current sapi executable
     if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) {
         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;
         }
     }
     $dirs = array(PHP_BINDIR);
     if (Symfony_Process_ProcessUtils::isWindows()) {
         $dirs[] = 'C:\\xampp\\php\\';
     }
     return $this->executableFinder->find('php', false, $dirs);
 }
 /**
  * Finds an executable by name.
  *
  * @param string $name      The executable name (without the extension)
  * @param string $default   The default to return if no executable is found
  * @param array  $extraDirs Additional dirs to check into
  *
  * @return string The executable path or default value
  */
 public function find($name, $default = null, array $extraDirs = array())
 {
     if (ini_get('open_basedir')) {
         $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
         $dirs = array();
         foreach ($searchPath as $path) {
             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') : getenv('Path')), $extraDirs);
     }
     $suffixes = array('');
     if (Symfony_Process_ProcessUtils::isWindows()) {
         $pathExt = getenv('PATHEXT');
         $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
     }
     foreach ($suffixes as $suffix) {
         foreach ($dirs as $dir) {
             if (is_file($file = $dir . DIRECTORY_SEPARATOR . $name . $suffix) && (Symfony_Process_ProcessUtils::isWindows() || is_executable($file))) {
                 return $file;
             }
         }
     }
     return $default;
 }
Exemplo n.º 3
0
 /**
  * Updates the status of the process, reads pipes.
  *
  * @param bool $blocking Whether to use a blocking read call.
  */
 protected function updateStatus($blocking)
 {
     if (self::STATUS_STARTED !== $this->status) {
         return;
     }
     $this->processInformation = proc_get_status($this->process);
     $this->captureExitCode();
     $this->readPipes($blocking, Symfony_Process_ProcessUtils::isWindows() ? !$this->processInformation['running'] : true);
     if (!$this->processInformation['running']) {
         $this->close();
     }
 }
Exemplo n.º 4
0
 /**
  * Creates a Process instance and returns it.
  *
  * @return Symfony_Process_Process
  *
  * @throws LogicException In case no arguments have been provided
  */
 public function getProcess()
 {
     if (0 === count($this->prefix) && 0 === count($this->arguments)) {
         throw new Symfony_Process_Exception_LogicException('You must add() command arguments before calling getProcess().');
     }
     $options = $this->options;
     $arguments = array_merge($this->prefix, $this->arguments);
     $script = implode(' ', array_map(array('Symfony_Process_ProcessUtils', 'escapeArgument'), $arguments));
     if ($this->inheritEnv) {
         // include $_ENV for BC purposes
         $env = Symfony_Process_ProcessUtils::arrayReplace($_ENV, $_SERVER, $this->env);
     } else {
         $env = $this->env;
     }
     $process = new Symfony_Process_Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
     if ($this->outputDisabled) {
         $process->disableOutput();
     }
     return $process;
 }
Exemplo n.º 5
0
 public function restore_db($fileName)
 {
     if (!$fileName) {
         throw new Exception('Cannot access database file.');
     }
     $port = 0;
     $host = DB_HOST;
     if (strpos(DB_HOST, ':') !== false) {
         list($host, $port) = explode(':', DB_HOST);
     }
     $socket = false;
     if (strpos(DB_HOST, '/') !== false || strpos(DB_HOST, '\\') !== false) {
         $socket = true;
         $host = end(explode(':', DB_HOST));
     }
     if ($socket) {
         $connection = array('--socket=' . $host);
     } else {
         $connection = array('--host=' . $host);
         if (!empty($port)) {
             $connection[] = '--port=' . $port;
         }
     }
     $mysql = mwp_container()->getExecutableFinder()->find('mysql', 'mysql');
     $arguments = array_merge(array($mysql, '--user='******'--password='******'--default-character-set=utf8', DB_NAME), $connection);
     $command = implode(' ', array_map(array('Symfony_Process_ProcessUtils', 'escapeArgument'), $arguments)) . ' < ' . Symfony_Process_ProcessUtils::escapeArgument($fileName);
     try {
         if (!mwp_is_shell_available()) {
             throw new MMB_Exception("Shell is not available");
         }
         $process = new Symfony_Process_Process($command, untrailingslashit(ABSPATH), $this->getEnv(), null, 3600);
         mwp_logger()->info('Database import process started', array('executable_location' => $mysql, 'command_line' => $process->getCommandLine()));
         $process->run();
         if (!$process->isSuccessful()) {
             throw new Symfony_Process_Exception_ProcessFailedException($process);
         }
     } catch (Symfony_Process_Exception_ProcessFailedException $e) {
         //unlink($fileName);
         mwp_logger()->error('Database import process failed', array('process' => $e->getProcess()));
         throw $e;
     } catch (Exception $e) {
         //unlink($fileName);
         mwp_logger()->error('Error while trying to execute database import process', array('exception' => $e));
         throw $e;
     }
     mwp_logger()->info('Database import process finished');
     //        unlink($fileName);
 }