/** * Closes process resource, closes file handles, sets the exitcode. * * @return Integer The exitcode */ private function close() { $exitcode = -1; $this->processPipes->close(); if (is_resource($this->process)) { $exitcode = proc_close($this->process); } $this->exitcode = $this->exitcode !== null ? $this->exitcode : -1; $this->exitcode = -1 != $exitcode ? $exitcode : $this->exitcode; if (-1 == $this->exitcode && null !== $this->fallbackExitcode) { $this->exitcode = $this->fallbackExitcode; } elseif (-1 === $this->exitcode && $this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) { // if process has been signaled, no exitcode but a valid termsig, apply unix convention $this->exitcode = 128 + $this->processInformation['termsig']; } return $this->exitcode; }
/** * Stops the process. * * @param integer|float $timeout The timeout in seconds * * @return integer The exit-code of the process * * @throws RuntimeException if the process got signaled */ public function stop($timeout = 10) { $timeoutMicro = microtime(true) + $timeout; if ($this->isRunning()) { proc_terminate($this->process); while ($this->isRunning() && microtime(true) < $timeoutMicro) { usleep(1000); } if (!defined('PHP_WINDOWS_VERSION_BUILD') && $this->isRunning()) { proc_terminate($this->process, SIGKILL); } $this->processPipes->close(); $exitcode = proc_close($this->process); $this->exitcode = -1 === $this->processInformation['exitcode'] ? $exitcode : $this->processInformation['exitcode']; } $this->status = self::STATUS_TERMINATED; return $this->exitcode; }
/** * Closes process resource, closes file handles, sets the exitcode. * * @return int The exitcode */ private function close() { $this->processPipes->close(); if (is_resource($this->process)) { proc_close($this->process); } $this->exitcode = $this->processInformation['exitcode']; $this->status = self::STATUS_TERMINATED; if (-1 === $this->exitcode) { if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) { // if process has been signaled, no exitcode but a valid termsig, apply Unix convention $this->exitcode = 128 + $this->processInformation['termsig']; } elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { $this->processInformation['signaled'] = true; $this->processInformation['termsig'] = -1; } } // Free memory from self-reference callback created by buildCallback // Doing so in other contexts like __destruct or by garbage collector is ineffective // Now pipes are closed, so the callback is no longer necessary $this->callback = null; return $this->exitcode; }