OpenSwoole\Http\Response->goaway()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Http\Response->goaway(int $errorCode, string $debugData): void

Parameters

errorCode

Set the HTTP2 error code for going away, see the error code list

debugData

HTTP2 debug message in the GOAWAY packet

Return

none

Description

Send HTTP2 GOAWAY packet to the HTTP2 client, then disconnect the connection gracefully after processing all existing requests.

This method is only available to HTTP2 enabled servers.

A server is entitled to close a connection at any time, for any reason. The GOAWAY frame/packet is used to indicate what was the last error available as to why the connection was closed. You use this feature to indicate the client about the connection shutdown or fatal error conditions.

This method must be called before the $response->end method.

Usable Error Codes

  • SW_HTTP2_ERROR_NO_ERROR = 0
  • SW_HTTP2_ERROR_PROTOCOL_ERROR = 1
  • SW_HTTP2_ERROR_INTERNAL_ERROR = 2
  • SW_HTTP2_ERROR_FLOW_CONTROL_ERROR = 3
  • SW_HTTP2_ERROR_SETTINGS_TIMEOUT = 4
  • SW_HTTP2_ERROR_STREAM_CLOSED = 5
  • SW_HTTP2_ERROR_FRAME_SIZE_ERROR = 6
  • SW_HTTP2_ERROR_REFUSED_STREAM = 7
  • SW_HTTP2_ERROR_CANCEL = 8
  • SW_HTTP2_ERROR_COMPRESSION_ERROR = 9
  • SW_HTTP2_ERROR_CONNECT_ERROR = 10
  • SW_HTTP2_ERROR_ENHANCE_YOUR_CALM = 11
  • SW_HTTP2_ERROR_INADEQUATE_SECURITY = 12

Example

<?php

$server = new OpenSwoole\HTTP\Server('127.0.0.1', 9090, OpenSwoole\Server::SIMPLE_MODE);

$server->set([
    'worker_num' => 1,
    'log_file' => '/dev/null',
    'open_http2_protocol' => true
]);

$server->on('Request', function(OpenSwoole\HTTP\Request $request, OpenSwoole\HTTP\Response $response)
{
    $response->goaway(OpenSwoole\Constant::HTTP2_ERROR_NO_ERROR, 'NO_ERROR');

    $response->end($request->rawcontent());
});

$server->start();
Last updated on September 20, 2022