コード例 #1
0
 /**
  * Waits for the process to terminate.
  *
  * 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.
  *
  * @param callback|null $callback A valid PHP callback
  *
  * @return integer The exitcode of the process
  *
  * @throws RuntimeException When process timed out
  * @throws RuntimeException When process stopped after receiving signal
  */
 public function wait($callback = null)
 {
     $this->updateStatus(false);
     if (null !== $callback) {
         $this->callback = $this->buildCallback($callback);
     }
     do {
         $this->checkTimeout();
         $running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles();
         $close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;
         $this->readPipes(true, $close);
     } while ($running);
     while ($this->isRunning()) {
         usleep(1000);
     }
     $this->processPipes->close();
     $exitcode = proc_close($this->process);
     if ($this->processInformation['signaled']) {
         if ($this->isSigchildEnabled()) {
             throw new RuntimeException('The process has been signaled.');
         }
         throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
     }
     $this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
     if (-1 == $this->exitcode && null !== $this->fallbackExitcode) {
         $this->exitcode = $this->fallbackExitcode;
     }
     return $this->exitcode;
 }
コード例 #2
0
ファイル: Process.php プロジェクト: rajdamaciej/mycms
 /**
  * Waits for the process to terminate.
  *
  * 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.
  *
  * @param callback|null $callback A valid PHP callback
  *
  * @return int The exitcode of the process
  *
  * @throws RuntimeException When process timed out
  * @throws RuntimeException When process stopped after receiving signal
  * @throws LogicException   When process is not yet started
  */
 public function wait($callback = null)
 {
     $this->requireProcessIsStarted(__FUNCTION__);
     $this->updateStatus(false);
     if (null !== $callback) {
         $this->callback = $this->buildCallback($callback);
     }
     do {
         $this->checkTimeout();
         $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->hasOpenHandles();
         $close = '\\' !== DIRECTORY_SEPARATOR || !$running;
         $this->readPipes(true, $close);
     } while ($running);
     while ($this->isRunning()) {
         usleep(1000);
     }
     if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
         throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
     }
     return $this->exitcode;
 }
コード例 #3
0
ファイル: Process.php プロジェクト: TuxCoffeeCorner/tcc
 /**
  * Waits for the process to terminate.
  *
  * 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.
  *
  * @param callable|null $callback A valid PHP callback
  *
  * @return integer The exitcode of the process
  *
  * @throws RuntimeException When process timed out
  * @throws RuntimeException When process stopped after receiving signal
  * @throws LogicException   When process is not yet started
  */
 public function wait($callback = null)
 {
     $this->requireProcessIsStarted(__FUNCTION__);
     $this->updateStatus(false);
     if (null !== $callback) {
         $this->callback = $this->buildCallback($callback);
     }
     do {
         $this->checkTimeout();
         $running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles();
         $close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;
         $this->readPipes(true, $close);
     } while ($running);
     while ($this->isRunning()) {
         usleep(1000);
     }
     if ($this->processInformation['signaled']) {
         throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
     }
     return $this->exitcode;
 }