public function stop(bool $throwException = false, bool $clearPidFileOnException = false): void
    {
        $this->logger->notice('Stopping server');

        try {
            $pid = $this->getPid();
            $running = $this->isProcessRunning(true);
            if (!$running) {
                if ($throwException) {
                    $msg = "Cannot stop: pid exists (${pid}) but server process is not running (throws_exception=true)";
                    $this->logger->notice("Stop failed: ${msg}");
                    throw new Exception\StopFailedException($msg);
                }

                return;
            }
        } catch (Exception\PidNotFoundException $e) {
            if ($throwException) {
                $msg = 'Cannot stop server: pid file not found (was the server started ?)';
                $this->logger->notice("Stop failed: $msg");
                if ($clearPidFileOnException) {
                    $this->clearPidFile();
                }
                throw new Exception\StopFailedException($msg, 0, $e);
            }

            return;
        }

        $killed = $this->process->kill($pid, true);

        try {
            if (!$killed) {
                $msg = "Cannot kill standalone server process '$pid', seems to not exists.";
                $this->logger->notice("Stop failed: $msg");
                throw new Exception\RuntimeException($msg);
            }
        } catch (Exception\RuntimeException $e) {
            if ($throwException) {
                $this->clearPidFile();
                throw $e;
            }
        }

        // Server successfully stopped let's clear the pid
        $this->clearPidFile();
        $this->started = false;
    }