예제 #1
0
 /**
  * Returns incremental process output (even if empty string) or false if the process has finished
  * successfully and all output was already returned.
  *
  * @throws Symfony_Process_Exception_ProcessFailedException If the process did not exit successfully.
  *
  * @internal
  *
  * @return string|false
  */
 public function getIncrementalOutput()
 {
     if (!$this->ran) {
         $this->ran = true;
         try {
             $this->process->start();
         } catch (Symfony_Process_Exception_ExceptionInterface $e) {
             throw new Symfony_Process_Exception_ProcessFailedException($this->process);
         }
     }
     if ($this->process->isRunning()) {
         $output = $this->process->getIncrementalOutput();
         $this->process->clearOutput();
         if (strlen($output) < Symfony_Process_Pipes_PipesInterface::CHUNK_SIZE) {
             // Don't hog the processor while waiting for incremental process output.
             usleep(100000);
         }
         // The stream will be read again because we're returning a string.
         return (string) $output;
     } else {
         if (!$this->process->isSuccessful()) {
             throw new Symfony_Process_Exception_ProcessFailedException($this->process);
         }
         $output = $this->process->getIncrementalOutput();
         $this->process->clearOutput();
         // The process has finished and is successful. This part will probably get run twice,
         // first time we'll return final output, second time we'll return 'false' and break the loop.
         return strlen($output) ? $output : false;
     }
 }
 public function __construct(Symfony_Process_Process $process)
 {
     if ($process->isSuccessful()) {
         throw new Symfony_Process_Exception_InvalidArgumentException('Expected a failed process, but the given process was successful.');
     }
     $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText());
     if (!$process->isOutputDisabled()) {
         $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput());
     }
     parent::__construct($error);
     $this->process = $process;
 }
예제 #3
0
function mwp_is_nio_shell_available()
{
    static $check;
    if (isset($check)) {
        return $check;
    }
    try {
        $process = new Symfony_Process_Process("cd .", dirname(__FILE__), array(), null, 1);
        $process->run();
        $check = $process->isSuccessful();
    } catch (Exception $e) {
        $check = false;
    }
    return $check;
}
예제 #4
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);
 }