OpenSwoole\WebSocket\Server->exists(...)

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

Declaration

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

Parameters

fd

The file descriptor of the WebSocket connection, it can be found from the frame object.

Return

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

Description

Check if the TCP connection exists and is in an active state. This is a good way to check if the client is present. The method is inherited from OpenSwoole\Server->exists().

Note: This method only checks the TCP connection, it also returns true for a connection that has not completed the WebSocket handshake. Use isEstablished() to check specifically for an established WebSocket connection.

Example

<?php
$server->on('Message', function (OpenSwoole\WebSocket\Server $server, $frame)
{
    if($server->exists($frame->fd))
    {
      echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
      $server->push($frame->fd, "This is a message from the server.");
    }
    else
    {
      echo "Connection does not exist\n";
    }
});
Last updated on November 20, 2026