/** * @param resource $socket Stream socket resource. * @param bool $autoClose True to close the resource on destruct, false to leave it open. */ public function __construct($socket, bool $autoClose = true) { parent::__construct($socket, $autoClose); try { list($this->remoteAddress, $this->remotePort) = getName($socket, true); list($this->localAddress, $this->localPort) = getName($socket, false); } catch (FailureException $exception) { $this->close(); } }
/** * Closes channel and socket if still open. */ private function close() { if (null !== $this->pipe && $this->pipe->isOpen()) { $this->pipe->close(); } if (is_resource($this->socket)) { fclose($this->socket); } $this->thread = null; $this->channel = null; }
/** * {@inheritdoc} */ public function kill() { if ($this->isRunning()) { // Forcefully kill the process using SIGKILL. posix_kill($this->pid, SIGKILL); } if (null !== $this->pipe && $this->pipe->isOpen()) { $this->pipe->close(); } // "Detach" from the process and let it die asynchronously. $this->pid = 0; $this->channel = null; }