OpenSwoole\Http\Response->ping()

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

Declaration

<?php OpenSwoole\Http\Response->ping(): bool

Parameters

Return

Returns true when the PING frame was sent, otherwise false.

Description

Send an HTTP/2 PING frame to the client of the current HTTP/2 connection.

This method is only available for HTTP/2 connections, enable open_http2_protocol on the server. For an HTTP/1.1 or WebSocket connection it returns false with the warning fd[...] is not a HTTP2 conncetion. To ping a WebSocket client, push a frame with the opcode WEBSOCKET_OPCODE_PING.

Example

<?php
$server = new OpenSwoole\Http\Server('127.0.0.1', 9501, OpenSwoole\Server::SIMPLE_MODE, OpenSwoole\Constant::SOCK_TCP | OpenSwoole\Constant::SSL);

$server->set([
    'open_http2_protocol' => true,
    'ssl_cert_file' => __DIR__ . '/ssl.crt',
    'ssl_key_file' => __DIR__ . '/ssl.key',
]);

$server->on('Request', function(OpenSwoole\Http\Request $request, OpenSwoole\Http\Response $response)
{
    $response->ping();
    $response->end('Hello');
});

$server->start();
Last updated on November 20, 2026