You are here

public function Process::stop in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/process/Process.php \Symfony\Component\Process\Process::stop()

Stops the process.

Parameters

int|float $timeout The timeout in seconds:

int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL:

Return value

int The exit-code of the process

Throws

RuntimeException if the process got signaled

2 calls to Process::stop()
Process::checkTimeout in vendor/symfony/process/Process.php
Performs a check between the timeout definition and the time the process started.
Process::__destruct in vendor/symfony/process/Process.php

File

vendor/symfony/process/Process.php, line 772

Class

Process
Process is a thin wrapper around proc_* functions to easily start independent PHP processes.

Namespace

Symfony\Component\Process

Code

public function stop($timeout = 10, $signal = null) {
  $timeoutMicro = microtime(true) + $timeout;
  if ($this
    ->isRunning()) {
    if ('\\' === DIRECTORY_SEPARATOR && !$this
      ->isSigchildEnabled()) {
      exec(sprintf('taskkill /F /T /PID %d 2>&1', $this
        ->getPid()), $output, $exitCode);
      if ($exitCode > 0) {
        throw new RuntimeException('Unable to kill the process');
      }
    }

    // given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
    $this
      ->doSignal(15, false);
    do {
      usleep(1000);
    } while ($this
      ->isRunning() && microtime(true) < $timeoutMicro);
    if ($this
      ->isRunning() && !$this
      ->isSigchildEnabled()) {
      if (null !== $signal || defined('SIGKILL')) {

        // avoid exception here :
        // process is supposed to be running, but it might have stop
        // just after this line.
        // in any case, let's silently discard the error, we can not do anything
        $this
          ->doSignal($signal ?: SIGKILL, false);
      }
    }
  }
  $this
    ->updateStatus(false);
  if ($this->processInformation['running']) {
    $this
      ->close();
  }
  return $this->exitcode;
}