Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1
<?php OpenSwoole\Http\Response->ping(): bool
Returns true when the PING frame was sent, otherwise false.
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.
<?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();