OpenSwoole Server exists()

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

Declaration

<?php OpenSwoole\Server->exists(int $fd): bool

Parameters

fd

The session ID (file descriptor number) of the client connection you want to check

Return

success

Returns true if the connection exists and is not closed, otherwise it returns false.

Description

Check whether the $fd which indicates a TCP client connection exists or not.

Returns true if it does and false if it does not exist or is already closed. For an SSL connection, false is also returned until the TLS handshake has completed.

The server must be running, calling this method before $server->start() returns false with a warning.

This method does no IO operations as it is based off shared memory.

Example

<?php
$server->on('Receive', function (OpenSwoole\Server $server, int $fd, int $reactorId, string $data)
{
    if ($server->exists($fd)) {
        $server->send($fd, "OK\n");
    }
});
Last updated on November 20, 2026