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\Server->exists(int $fd): bool
The session ID (file descriptor number) of the client connection you want to check
Returns true if the connection exists and is not closed, otherwise it returns false.
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.
<?php
$server->on('Receive', function (OpenSwoole\Server $server, int $fd, int $reactorId, string $data)
{
if ($server->exists($fd)) {
$server->send($fd, "OK\n");
}
});