Stops the process.
integer|float $timeout The timeout in seconds:
integer $signal A posix signal to send in case the process has not stop at timeout, default is SIGKILL:
integer The exit-code of the process
RuntimeException if the process got signaled
public function stop($timeout = 10, $signal = null) {
$timeoutMicro = (int) $timeout * 1000000.0;
if ($this
->isRunning()) {
proc_terminate($this->process);
$time = 0;
while (1 == $this
->isRunning() && $time < $timeoutMicro) {
$time += 1000;
usleep(1000);
}
if ($this
->isRunning() && !$this
->isSigchildEnabled()) {
if (null !== $signal || defined('SIGKILL')) {
$this
->signal($signal ?: SIGKILL);
}
}
foreach ($this->pipes as $pipe) {
fclose($pipe);
}
$this->pipes = array();
$exitcode = proc_close($this->process);
$this->exitcode = -1 === $this->processInformation['exitcode'] ? $exitcode : $this->processInformation['exitcode'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
foreach ($this->fileHandles as $fileHandle) {
fclose($fileHandle);
}
$this->fileHandles = array();
}
}
$this->status = self::STATUS_TERMINATED;
return $this->exitcode;
}