コード例 #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;
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function start($callback = null)
 {
     if (null === $this->getCommandLine()) {
         throw new Symfony_Process_Exception_RuntimeException('Unable to find the PHP executable.');
     }
     parent::start($callback);
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: functions.php プロジェクト: tconte252/haute-inhabit
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;
}
コード例 #5
0
ファイル: Process.php プロジェクト: onedaylabs/onedaylabs.com
 /**
  * Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
  *
  * @return bool
  */
 protected function isSigchildEnabled()
 {
     if (null !== self::$sigchild) {
         return self::$sigchild;
     }
     if (!function_exists('phpinfo')) {
         return self::$sigchild = false;
     }
     ob_start();
     phpinfo(INFO_GENERAL);
     return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
 }
コード例 #6
0
 public function __construct(Symfony_Process_Process $process, $timeoutType)
 {
     $this->process = $process;
     $this->timeoutType = $timeoutType;
     parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout()));
 }
コード例 #7
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;
 }
コード例 #8
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);
 }
コード例 #9
0
 /**
  * Creates a new WindowsPipes instance.
  *
  * @param Symfony_Process_Process $process The process
  * @param $input
  *
  * @return Symfony_Process_Pipes_WindowsPipes
  */
 public static function create(Symfony_Process_Process $process, $input)
 {
     return new self($process->isOutputDisabled(), $input);
 }