Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-25.2.0 | composer require openswoole/core:22.1.5
<?php OpenSwoole\WebSocket\Server->isEstablished(int $fd): bool
The fd of the WebSocket connection, it can found from the server event callback parameter $fd
or from the Swoole data frame object. The fd
must be a valid WebSocket connection fd
.
If success, it returns true
, otherwise it returns false
Check if the WebSocket connection is established, has completed the handshake stage and that the WebSocket connection is valid.
This method is different from exists()
because that is used only to check TCP connections, not WebSocket connections. You can use isEstablished()
to check for valid WebSocket TCP connections.
Inside a normal server.php
file, we can start up a WebSocket server which responds to HTTP requests and broadcasts back to all clients who are connected. In this example we are using the function isEstablished
to check if the WebSocket client is still connected and has completed the handshake stage, allowing us to send a message back to the clients.
Accessing file descriptor through event callback parameters