예제 #1
0
 /**
  * Starts the process and returns after writing the input to STDIN.
  *
  * This method blocks until all STDIN data is sent to the process then it
  * returns while the process runs in the background.
  *
  * The termination of the process can be awaited with wait().
  *
  * The callback receives the type of output (out or err) and some bytes from
  * the output in real-time while writing the standard input to the process.
  * It allows to have feedback from the independent process during execution.
  * If there is no callback passed, the wait() method can be called
  * with true as a second parameter then the callback will get all data occurred
  * in (and since) the start call.
  *
  * @param callable|null $callback A PHP callback to run whenever there is some
  *                                output available on STDOUT or STDERR
  *
  * @throws RuntimeException When process can't be launched
  * @throws RuntimeException When process is already running
  * @throws LogicException   In case a callback is provided and output has been disabled
  */
 public function start($callback = null)
 {
     if ($this->isRunning()) {
         throw new Symfony_Process_Exception_RuntimeException('Process is already running');
     }
     if ($this->outputDisabled && null !== $callback) {
         throw new Symfony_Process_Exception_LogicException('Output has been disabled, enable it to allow the use of a callback.');
     }
     $this->resetProcessData();
     $this->starttime = $this->lastOutputTime = microtime(true);
     $this->callback = $this->buildCallback($callback);
     $descriptors = $this->getDescriptors();
     $commandline = $this->commandline;
     if (Symfony_Process_ProcessUtils::isWindows() && $this->enhanceWindowsCompatibility) {
         $commandline = 'cmd /V:ON /E:ON /C "(' . $commandline . ')';
         foreach ($this->processPipes->getFiles() as $offset => $filename) {
             $commandline .= ' ' . $offset . '>' . Symfony_Process_ProcessUtils::escapeArgument($filename);
         }
         $commandline .= '"';
         if (!isset($this->options['bypass_shell'])) {
             $this->options['bypass_shell'] = true;
         }
     }
     $this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
     if (!is_resource($this->process)) {
         throw new Symfony_Process_Exception_RuntimeException('Unable to launch a new process.');
     }
     $this->status = self::STATUS_STARTED;
     if ($this->tty) {
         return;
     }
     $this->updateStatus(false);
     $this->checkTimeout();
 }
예제 #2
0
파일: Backup.php 프로젝트: jimrucinski/Vine
 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);
 }