OpenSwoole Server heartbeat()

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

Declaration

<?php OpenSwoole\Server->heartbeat(bool $ifCloseConnection = true): bool|array

Parameters

ifCloseConnection

Whether to close any detected timed out connections based on the server configuration options that are set.

Return

bool|array

If successful, an array of closed connection fds are returned, otherwise if something went wrong or no connections are closed/found false is returned instead.

Description

This method is difference from the heartbeat_check_interval server configuration, which is passive. The heartbeat method actively checks all connections to see if they have exceeded the agreed heartbeat timeout set within the server configuration options.

By default, calling this method will close any idle connections but you can disable this by passing false.

Example

<?php
$closeFdArrary = $server->heartbeat();

var_dump($closeFdArrary);
Last updated on September 1, 2022