### Install websocket-php with Composer Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/README.md Preferred installation method using Composer. Ensure you have Composer installed and configured. ```bash composer require phrity/websocket ``` -------------------------------- ### Install and Update Dependencies with Composer Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Contributing.md Use these Make commands to manage project dependencies. 'make install' installs dependencies, and 'make update' updates them. ```bash # Install dependencies make install ``` ```bash # Update dependencies make update ``` -------------------------------- ### Instantiate Configuration Class Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md All constructor arguments for the Configuration class are optional. This example shows the full signature. ```php $configuration = new WebSocket\Configuration( Psr\Log\LoggerInterface $logger, Phrity\Net\Context $context, int|float $timeout, int $frameSize, bool $persistent, int $maxConnections, ); ``` -------------------------------- ### Working with Middleware Stacks Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/Creating.md Examples of using `ProcessStack`, `ProcessHttpStack`, and `ProcessTickStack` to manage middleware execution flow. ```php // Get the received Message, possibly handled by other middlewares $message = $stack->handleIncoming(); ``` ```php // Forward the Message to be sent, possibly handled by other middlewares $message = $stack->handleOutgoing($message); ``` ```php // Get the received HTTP request/response message, possibly handled by other middlewares $message = $stack->handleHttpIncoming(); ``` ```php // Forward the HTTP request/response message to be sent, possibly handled by other middlewares $message = $stack->handleHttpOutgoing($message); ``` ```php // Forward the Tick operation, possibly handled by other middlewares $stack->handleTick(); ``` -------------------------------- ### Delegating Server Try It Example Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Examples.md Demonstrates how to set up and test the delegating server by running an echo server as the remote and sending a message through the delegating server. ```bash # Start remote server on 8000 php examples/echoserver.php --port 8000 # Start delegating server on port 8001, with above echoserver as remote php examples/delegating_server.php --remote=ws://127.0.0.1:8000 --port=8001 # Send message to delegating server php examples/send.php --uri=ws://127.0.0.1:8001 "A message to delegate" ``` -------------------------------- ### Start WebSocket Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Initiates the WebSocket server to continuously listen for and process incoming messages. ```php $server->start(); ``` -------------------------------- ### Server Log Output Example Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Examples.md An example of the log output generated by the WebSocket server, showing connection status, message reception, and transmission details. ```text info | Server listening to port 80 debug | Wrote 129 of 129 bytes. info | Server connected to port 80 info | Received 'text' message debug | Wrote 9 of 9 bytes. info | Sent 'text' message debug | Received 'close', status: 1000. debug | Wrote 32 of 32 bytes. info | Sent 'close' message info | Received 'close' message ``` -------------------------------- ### Setting and Getting Configuration for WebSocket Classes Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Demonstrates how to set and retrieve configuration objects for the Connection, FrameHandler, and MessageHandler classes. Ensure you have the necessary configuration object before instantiation. ```php // Connection class $connection = new WebSocket\Connection(..., configuration: $configuration); $configuration = $connection->getConfiguration(); $connection->setConfiguration($configuration); // FrameHandler class $frameHandler = new WebSocket\Frame\FrameHandler(..., configuration: $configuration); $configuration = $frameHandler->getConfiguration(); $frameHandler->setConfiguration($configuration); // MessageHandler class $messageHandler = new WebSocket\Message\MessageHandler(..., configuration: $configuration); $configuration = $messageHandler->getConfiguration(); $messageHandler->setConfiguration($configuration); ``` -------------------------------- ### Get and Set Configuration on Client/Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Retrieve or update the Configuration object associated with a Client or Server instance. ```php $configuration = $client->getConfiguration(); $client->setConfiguration($configuration); $configuration = $server->getConfiguration(); $server->setConfiguration($configuration); ``` -------------------------------- ### Setting Up Message Listeners Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md Configures a WebSocket client to listen for incoming Text and Binary messages. When a message of a specific type is received, the corresponding callback function is executed. The `start()` method is used to begin processing messages, and `isRunning()` checks the client's status. ```php $client = new WebSocket\Client("wss://echo.websocket.org/"); $client // Listen to incoming Text messages ->onText(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Text $message) { // Act on incoming message }) // Listen to incoming Binary messages ->onBinary(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Binary $message) { // Act on incoming message }) ->start(); ; $client->isRunning(); // => True if currently running ``` -------------------------------- ### WebSocket\Trait\ConfigurationTrait::getConfiguration Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Gets the current configuration object. ```APIDOC ## WebSocket\Trait\ConfigurationTrait::getConfiguration ### Description Gets the current configuration object. ### Method public ### Signature getConfiguration(): WebSocket\Configuration ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - WebSocket\Configuration: The current configuration object. #### Response Example None ``` -------------------------------- ### Get Writable Connections Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Returns a list of connections that are currently writable, indicating they are ready to send data. ```php $server->getWritableConnections(); ``` -------------------------------- ### Sending WebSocket Messages (Convenience Methods) Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md Provides examples of using convenience methods (`text`, `binary`, `ping`, `pong`, `close`) to send different types of WebSocket messages. These methods offer a more concise way to send messages compared to creating message instances manually. ```php $client->text("Server sends a message"); $client->binary($binary); $client->ping("My ping"); $client->pong("My pong"); $client->close(1000, "Closing now"); ``` -------------------------------- ### WebSocket\Server Methods Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Provides methods for managing a WebSocket server, including starting, stopping, handling connections, and configuring server settings. ```APIDOC ## WebSocket\Server ### Description Manages a WebSocket server instance, allowing for configuration, connection handling, and middleware integration. ### Methods - **__construct(int $port = 80, bool $ssl = false, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null)**: Initializes a new WebSocket server instance. - **__toString(): string**: Returns a string representation of the server. - **addMiddleware(WebSocket\Middleware\MiddlewareInterface $middleware): self**: Adds a middleware to the server. - **disconnect(): void**: Disconnects all active client connections. - **getConnectionCount(): int**: Gets the number of active connections. - **getConnections(): array**: Retrieves all active connections. - **getContext(): Phrity\Net\Context**: Gets the server context. - **getFrameSize(): int**: Gets the maximum frame size. - **getIdentity(): string**: Gets the server identity. - **getPort(): int**: Gets the server port. - **getReadableConnections(): array**: Gets connections that are ready for reading. - **getScheme(): string**: Gets the server scheme (ws or wss). - **getStream(): Phrity\Net\SocketServer**: Gets the underlying socket server stream. - **getTimeout(): int|float**: Gets the stream timeout. - **getWritableConnections(): array**: Gets connections that are ready for writing. - **isRunning(): bool**: Checks if the server is running. - **isSsl(): bool**: Checks if the server is using SSL. - **send(WebSocket\Message\Message $message): WebSocket\Message\Message**: Sends a message to all connected clients. - **setContext(Phrity\Net\Context|array $context): self**: Sets the server context. - **setFrameSize(int $frameSize): self**: Sets the maximum frame size. - **setHttpFactory(Phrity\Http\HttpFactory $httpFactory): self**: Sets the HTTP factory. - **setLogger(Psr\Log\LoggerInterface $logger): void**: Sets the logger for the server. - **setMaxConnections(int|null $maxConnections): self**: Sets the maximum number of connections. - **setStreamFactory(Phrity\Net\StreamFactory $streamFactory): self**: Sets the stream factory. - **setTimeout(int|float $timeout): self**: Sets the stream timeout. - **shutdown(int $closeStatus = 1001): void**: Shuts down the server gracefully. - **start(int|float|null $timeout = null): void**: Starts the WebSocket server. - **stop(): void**: Stops the WebSocket server. ``` -------------------------------- ### WebSocket Server for Continuous Listening Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/README.md Implement a multi-connection WebSocket server for continuous listening. This server includes standard middlewares and an event handler for incoming text messages. The start method begins the server's operation. ```php $server = new WebSocket\Server(); $server // Add standard middlewares ->addMiddleware(new WebSocket\Middleware\CloseHandler()) ->addMiddleware(new WebSocket\Middleware\PingResponder()) // Listen to incoming Text messages ->onText(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Message $message) { // Act on incoming message echo "Got message: {$message->getContent()} \n"; // Possibly respond to client $connection->text("I got your your message"); }) ->start(); ``` -------------------------------- ### WebSocket Client for Continuous Subscription Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/README.md Configure a WebSocket client for continuous subscription to messages. It includes standard middlewares and an event listener for incoming text messages. The start method initiates the listening process. ```php $client = new WebSocket\Client("wss://echo.websocket.org/"); $client // Add standard middlewares ->addMiddleware(new WebSocket\Middleware\CloseHandler()) ->addMiddleware(new WebSocket\Middleware\PingResponder()) // Listen to incoming Text messages ->onText(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Message $message) { // Act on incoming message echo "Got message: {$message->getContent()} \n"; // Possibly respond to server $client->text("I got your your message"); }) ->start(); ``` -------------------------------- ### Self-Resuming Continuous Subscription Client Setup Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Examples.md Configures a WebSocket client for continuous subscription with automatic reconnection and message resumption. Includes essential middlewares for maintaining the connection and handling events. ```php use Psr\Http\Message{ ResponseInterface, RequestInterface, }; use WebSocket\Client; use WebSocket\Connection; use WebSocket\Exception\ExceptionInterface; use WebSocket\Message\Text; use WebSocket\Middleware{ CloseHandler, PingResponder, PingInterval, }; // Create client $client = new Client("wss://echo.websocket.org/"); $client // Add standard middlewares ->addMiddleware(new CloseHandler()) ->addMiddleware(new PingResponder()) // Add ping interval middleware as heartbeat to keep connection open ->addMiddleware(new PingInterval(interval: 30)) // Timeout should have same (or lower) value as interval ->setTimeout(30) ->onHandshake(function (Client $client, Connection $connection, RequestInterface $request, ResponseInterface $response) { // Initial message, typically some authorization or configuration // This will be called everytime the client connect or reconnect $client->text($initial_message); }) ->onText(function (Client $client, Connection $connection, Text $message) { // Act on incoming message $message->getContent(); // Possibly respond to server $client->text($some_message); }) ->onError(function (Client $client, Connection|null $connection, ExceptionInterface $exception) { // Act on exception if (!$client->isRunning()) { // Re-start if not running - will reconnect if necessary $client->start(); } }) // Start subscription ->start() ; ``` -------------------------------- ### Get Readable Connections Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Returns a list of connections that are currently readable, indicating they may have incoming data. ```php $server->getReadableConnections(); ``` -------------------------------- ### Get All Connections Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Retrieves a list of all current connections to the WebSocket server, regardless of their state. ```php $server->getConnections(); ``` -------------------------------- ### Adding Middlewares to WebSocket Client/Server (v2.x) Source: https://github.com/sirn-se/websocket-php/wiki/Migration-v1-→-v2 Version 2.x supports middlewares for extending functionality. Examples include adding a CloseHandler and a PingResponder, which were built-in in v1.x. ```php addMiddleware(new WebSocket\Middleware\CloseHandler()) addMiddleware(new WebSocket\Middleware\PingResponder()) ``` -------------------------------- ### Get Server Information Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Retrieves information about the WebSocket server, including its port, scheme, and SSL status. ```php echo "port: {$server->getPort()}\n"; echo "scheme: {$server->getScheme()}\n"; echo "ssl: {$server->isSsl()}\n"; ``` -------------------------------- ### WebSocket Server Control Methods Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Provides methods to manage the WebSocket server lifecycle, including starting, stopping, and shutting down the server, as well as managing connections and middleware. ```php public method addMiddleware(WebSocket\Middleware\MiddlewareInterface $middleware): self; public method disconnect(): void; public method getConnectionCount(): int; public method getConnections(): array; public method getContext(): Phrity\Net\Context; public method getFrameSize(): int; public method getIdentity(): string; public method getPort(): int; public method getReadableConnections(): array; public method getScheme(): string; public method getStream(): Phrity\Net\SocketServer; public method getTimeout(): int|float; public method getWritableConnections(): array; public method isRunning(): bool; public method isSsl(): bool; public method send(WebSocket\Message\Message $message): WebSocket\Message\Message; public method setContext(Phrity\Net\Context|array $context): self; public method setFrameSize(int $frameSize): self; public method setHttpFactory(Phrity\Http\HttpFactory $httpFactory): self; public method setLogger(Psr\Log\LoggerInterface $logger): void; public method setMaxConnections(int|null $maxConnections): self; public method setStreamFactory(Phrity\Net\StreamFactory $streamFactory): self; public method setTimeout(int|float $timeout): self; public method shutdown(int $closeStatus = 1001): void; public method start(int|float|null $timeout = null): void; public method stop(): void; ``` -------------------------------- ### Add DeflateCompressor to CompressionExtension Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/CompressionExtension.md Adds support for the permessage-deflate compression extension to the WebSocket connection. This is the basic setup for enabling compression. ```php $client_or_server->addMiddleware(new WebSocket\Middleware\CompressionExtension( new WebSocket\Middleware\CompressionExtension\DeflateCompressor() )); ``` -------------------------------- ### Provide Configuration to Client and Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Instantiate Client and Server classes by passing a Configuration object to their constructors. ```php $client = new WebSocket\Client( uri: $uri, configuration: $configuration, ); $server = new WebSocket\Server( port: $port, ssl: $ssl, configuration: $configuration, ); ``` -------------------------------- ### Get Connection Count Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Returns the total number of currently connected clients to the WebSocket server. ```php $server->getConnectionCount(); ``` -------------------------------- ### Run All Tests Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/tests/README.md Execute all unit tests for the project using the provided make command. ```bash make test ``` -------------------------------- ### Run Unit Tests and Generate Coverage Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Contributing.md Execute unit tests using Make. 'make test' runs the tests, and 'make coverage' generates a code coverage report. ```bash # Run unit tests make test ``` ```bash # Create coverage make coverage ``` -------------------------------- ### WebSocket\Trait\ConfigurationTrait::initConfiguration Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes the configuration object. ```APIDOC ## WebSocket\Trait\ConfigurationTrait::initConfiguration ### Description Initializes the configuration object. ### Method public ### Signature initConfiguration(WebSocket\Configuration|null $configuration = null): self ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - self: The instance of the class. #### Response Example None ``` -------------------------------- ### Setting Up Text and Binary Message Listeners Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Configures a WebSocket server to listen for and process incoming text and binary messages. ```php $server = new WebSocket\Server(); $server // Listen to incoming Text messages ->onText(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Text $message) { // Act on incoming message }) // Listen to incoming Binary messages ->onBinary(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Binary $message) { // Act on incoming message }) ->start(); ; ``` -------------------------------- ### Configure Network Context for WebSocket Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Add context options and parameters using Phrity\Net\Context. Defaults to an empty context. ```php // Create and configure Context $context = new Phrity\Net\Context(); $context->setOptions([ "ssl" => [ "verify_peer" => false, "verify_peer_name" => false, ], ]); // Configuration instance $configuration = new WebSocket\Configuration(context: $context); $configuration->setContext($context); $context = $configuration->getContext(); // Convenience getters/setters $context = $client->getContext(); $client->setContext($context); $context = $server->getContext(); $server->setContext($context); ``` -------------------------------- ### Accessing and Modifying WebSocket Connection Context Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Get the connection's context and manipulate its options, such as SSL verification. ```php $context = $connection->getContext(); $context->getOption("ssl", "verify_peer"); $context->setOption("ssl", "verify_peer", false); ``` -------------------------------- ### Retrieving WebSocket Connection Information Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Get the local and remote names of a WebSocket connection, and manage associated metadata. ```php // Get local name for connection $connection->getName(); // Get remote name for connection $connection->getRemoteName(); // Get and set associated meta data on connection $connection->setMeta('myMetaData', $anything); $connection->getMeta('myMetaData'); // Trigger a tick event on connection $connection->tick(); ``` -------------------------------- ### Configure DeflateCompressor Options Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/CompressionExtension.md Configures the DeflateCompressor with optional arguments for server and client context takeover, and maximum window bits for LZ77 sliding window. These options allow fine-tuning of the compression behavior. ```php $deflateCompressor = new WebSocket\Middleware\CompressionExtension\DeflateCompressor( serverNoContextTakeover: false, // bool - Server disables context takeover clientNoContextTakeover: false, // bool - Client disables context takeover serverMaxWindowBits: 15, // int<8, 15> - Maximum bits for LZ77 sliding window used by Server clientMaxWindowBits: 15, // int<8, 15> - Maximum bits for LZ77 sliding window used by Client ); ``` -------------------------------- ### Configuring WebSocket Connection Timeout Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Set and get the timeout in seconds for read and write operations on a WebSocket connection. Default is 60 seconds. ```php $connection->setTimeout(300); // set timeout in seconds $connection->getTimeout(); // => current timeout in seconds ``` -------------------------------- ### SubprotocolNegotiation Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes SubprotocolNegotiation with a list of subprotocols and a requirement flag. ```php public method __construct(array $subprotocols, bool $require = false); ``` -------------------------------- ### WebSocket Client and Server Constructor (v2.x) Source: https://github.com/sirn-se/websocket-php/wiki/Migration-v1-→-v2 In v2.x, WebSocket clients and servers are instantiated differently than in v1.x. The client takes a URI, while the server requires SSL and port configuration. ```php new WebSocket\Client(string $uri) new WebSocket\Server(bool $ssl, int $port) ``` -------------------------------- ### Cloning and Modifying Configuration in v4 Source: https://github.com/sirn-se/websocket-php/wiki/Migration-v3-→-v4-(preliminary) Demonstrates how to clone an existing configuration object and modify its settings like logger, timeout, and frame size before applying it to a source object. This is the recommended approach for setting configuration on internal classes in v4. ```php $clonedConfiguration = clone $source->getConfiguration(); $clonedConfiguration->setLogger(...); $clonedConfiguration->setTimeout(...); $clonedConfiguration->setFrameSize(...); $source->setConfiguration($clonedConfiguration); ``` -------------------------------- ### Manual Connection Control Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md Manually connect to the WebSocket server if not already connected, and disconnect when necessary. The client automatically connects when sending messages or starting the listener. ```php if (!$client->isConnected()) { $client->connect(); } $client->disconnect(); ``` -------------------------------- ### WebSocket Server Configuration Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Constructs a new WebSocket server instance. Allows configuration of port, SSL, custom configurations, and stream factories. ```php public method __construct(int $port = 80, bool $ssl = false, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null); ``` -------------------------------- ### Sending WebSocket Messages (Instance) Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md Demonstrates sending various types of WebSocket messages (Text, Binary, Ping, Pong, Close) by creating instances of their respective classes and passing them to the `send()` method. ```php $client->send(new WebSocket\Message\Text("Server sends a message")); $client->send(new WebSocket\Message\Binary($binary)); $client->send(new WebSocket\Message\Ping("My ping")); $client->send(new WebSocket\Message\Text("My pong")); $client->send(new WebSocket\Message\Close(1000, "Closing now")); ``` -------------------------------- ### Registering Connection Listeners Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Listener.md Configure listeners for connection establishment (handshake) and disconnection events. The handshake listener provides different arguments for Client and Server. ```php $client_or_server // Called when a connection and handshake established ->onHandshake(function (WebSocket\Client|WebSocket\Server $client_or_server WebSocket\Connection $connection, Psr\Http\Message\RequestInterface|Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $respone) { // Act on connect }) // Called when a connection is closed ->onDisconnect(function (WebSocket\Client|WebSocket\Server $client_or_server, WebSocket\Connection $connection) { // Act on disconnect }) ; ``` -------------------------------- ### Adding Standard Middlewares to Client and Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware.md Demonstrates how to add CloseHandler and PingResponder middlewares to both a WebSocket client and server instance. These middlewares ensure standard WebSocket protocol operability. ```php $client ->addMiddleware(new WebSocket\Middleware\CloseHandler()) ->addMiddleware(new WebSocket\Middleware\PingResponder()) ; $server ->addMiddleware(new WebSocket\Middleware\CloseHandler()) ->addMiddleware(new WebSocket\Middleware\PingResponder()) ; ``` -------------------------------- ### Broadcasting Various Message Types via Server (Convenience Methods) Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Uses convenience methods on the Server instance to broadcast Text, Binary, Ping, Pong, and Close messages to all clients. ```php $server->text("Server sends a message"); $server->binary($binary); $server->ping("My ping"); $server->pong("My pong"); $server->close(1000, "Closing now"); ``` -------------------------------- ### Configure Persistent Connection for Client Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Enable persistent connections for the Client by setting 'persistent' to true. Defaults to false. ```php // Configuration instance $configuration = new WebSocket\Configuration(persistent: $persistent); $configuration->setPersistent($persistent); $persistent = $configuration->isPersistent(); // Convenience setter $client->setPersistent($persistent); ``` -------------------------------- ### WebSocket Client Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md The Client constructor requires a URI and optionally accepts Configuration and StreamFactory objects. The URI can be a string or an object implementing UriInterface. Supported schemas are 'ws' and 'wss'. ```php __construct( Psr\Http\Message\UriInterface|string $uri, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null, ); ``` -------------------------------- ### Runner Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes the Runner with a stream factory. ```php public method __construct(Phrity\Net\StreamFactory $streamFactory); ``` -------------------------------- ### WebSocket Configuration Methods (v2.x) Source: https://github.com/sirn-se/websocket-php/wiki/Migration-v1-→-v2 Version 2.x replaces the array-based constructor configuration of v1.x with dedicated setter methods for various options like logger, timeout, and headers. ```php setLogger(Psr\Log\LoggerInterface $logger) // logger setTimeout(int $timeout) // timeout setFrameSize(int $frameSize) // fragment_size setPersistent(bool $persistent) // persistent setContext(array $context_as_array) // context addHeader(string $name, string $value) // headers ``` -------------------------------- ### Server Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Defines the constructor for the Server class, specifying default values for port and SSL, and allowing custom configurations and stream factories. ```php __construct( int $port = 80, bool $ssl = false, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null, ); ``` -------------------------------- ### Adding Standard Middlewares Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Client.md Illustrates how to add the `CloseHandler` and `PingResponder` middlewares to a WebSocket client. These middlewares ensure standard WebSocket protocol operability by automatically handling close requests and responding to ping messages. ```php $client = new WebSocket\Client("wss://echo.websocket.org/"); $client // Add CloseHandler middleware ->addMiddleware(new WebSocket\Middleware\CloseHandler()) // Add PingResponder middleware ->addMiddleware(new WebSocket\Middleware\PingResponder()) ; ``` -------------------------------- ### Run Static Analysis with PHPStan Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Contributing.md This Make command executes static analysis checks using PHPStan to ensure code quality and identify potential issues. ```bash # Run static analysis make stan ``` -------------------------------- ### Broadcasting Various Message Types via Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Demonstrates sending Text, Binary, Ping, Pong, and Close messages to all connected clients using the Server instance. ```php $server->send(new WebSocket\Message\Text("Server sends a message")); $server->send(new WebSocket\Message\Binary($binary)); $server->send(new WebSocket\Message\Ping("My ping")); $server->send(new WebSocket\Message\Text("My pong")); $server->send(new WebSocket\Message\Close(1000, "Closing now")); ``` -------------------------------- ### Configuration: Context Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Access and modify connection context options. ```APIDOC ## Configuration: Context ### Description Access and modify connection context options using the Phrity\Net\Context class. ### Methods - `getContext()`: Returns the connection's context object. ### Request Example ```php $context = $connection->getContext(); $context->getOption("ssl", "verify_peer"); $context->setOption("ssl", "verify_peer", false); ``` ``` -------------------------------- ### WebSocket Connection Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes a WebSocket connection with a stream, optional SSL support, and an HTTP factory. ```php public method __construct(Phrity\Net\SocketStream $stream, bool $ssl = false, Phrity\Http\HttpFactory|null $httpFactory = null); ``` -------------------------------- ### ProcessTickStack Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes a ProcessTickStack with a connection and an array of processors. ```php public method __construct(WebSocket\Connection $connection, array $processors); ``` -------------------------------- ### Create WebSocket Message Instances Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Message.md Instantiate different types of WebSocket messages. Text and Binary messages are for content, while Ping, Pong, and Close can optionally have content or status codes. ```php // Text and Binary message types $text = new WebSocket\Message\Text("Some text to be sent"); $binary = new WebSocket\Message\Binary(""); // Ping and Pong may optionally have content $ping = new WebSocket\Message\Ping(); $ping = new WebSocket\Message\Ping("Some text"); $pong = new WebSocket\Message\Pong(); $pong = new WebSocket\Message\Pong("Some text"); // Close may optionally have close status and content $close = new WebSocket\Message\Close(); $close = new WebSocket\Message\Close(1000); $close = new WebSocket\Message\Close(1000, "Some text"); ``` -------------------------------- ### ProcessStack Constructor Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Initializes a ProcessStack with a connection, message handler, and an array of processors. ```php public method __construct(WebSocket\Connection $connection, WebSocket\Message\MessageHandler $messageHandler, array $processors); ``` -------------------------------- ### Configure Logger for WebSocket Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Attach any PSR-3 compatible logger to the Configuration instance or directly to Client/Server. Defaults to NullLogger. ```php // Configuration instance $configuration = new WebSocket\Configuration(logger: $logger); $configuration->setLogger($logger); $logger = $configuration->getLogger(); // Convenience setters $client->setLogger($logger); $server->setLogger($logger); ``` -------------------------------- ### Configure Max Connections for Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Configuration.md Limit the maximum number of connections the Server will handle. Defaults to null (unlimited). ```php // Configuration instance $configuration = new WebSocket\Configuration(maxConnections: $maxConnections); $configuration->setMaxConnections($maxConnections); $maxConnections = $configuration->getMaxConnections(); // Convenience setter $server->setMaxConnections($maxConnections); ``` -------------------------------- ### WebSocket Client for Request/Response Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/README.md Set up a WebSocket client for a request/response interaction. This client supports standard middlewares for handling close and ping/pong operations. The receive method is blocking. ```php $client = new WebSocket\Client("wss://echo.websocket.org/"); $client // Add standard middlewares ->addMiddleware(new WebSocket\Middleware\CloseHandler()) ->addMiddleware(new WebSocket\Middleware\PingResponder()) ; // Send a message $client->text("Hello WebSocket.org!"); // Read response (this is blocking) $message = $client->receive(); echo "Got message: {$message->getContent()} \n"; // Close connection $client->close(); ``` -------------------------------- ### Add Multiple DeflateCompressor Instances with Priority Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/CompressionExtension.md Adds multiple DeflateCompressor instances with different configurations to the middleware. The client requests compression methods in the order they are added, and the server responds with the first match. This allows for fallback to default settings if a preferred configuration is not supported. ```php $client->addMiddleware(new WebSocket\Middleware\CompressionExtension( new WebSocket\Middleware\CompressionExtension\DeflateCompressor( serverNoContextTakeover: true, clientNoContextTakeover: true, ), new WebSocket\Middleware\CompressionExtension\DeflateCompressor(), )); ``` -------------------------------- ### Sending Various Message Types via Connection Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Shows how to send Text, Binary, Ping, Pong, and Close messages to a specific client using the Connection instance. ```php $connection->send(new WebSocket\Message\Text("Server sends a message")); $connection->send(new WebSocket\Message\Binary($binary)); $connection->send(new WebSocket\Message\Ping("My ping")); $connection->send(new WebSocket\Message\Text("My pong")); $connection->send(new WebSocket\Message\Close(1000, "Closing now")); ``` -------------------------------- ### Server-Side Subprotocol Negotiation Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/SubprotocolNegotiation.md Add the SubprotocolNegotiation middleware to a server, providing a list of supported subprotocols. The server will select the first requested protocol it supports. Access the selected subprotocol within message handlers using getMeta. ```php $server->addMiddleware(new WebSocket\Middleware\SubprotocolNegotiation([ 'subproto-1', 'subproto-2', 'subproto-3', ])); $server->->onText(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Message $message) { $selected_subprotocol = $connection->getMeta('subprotocolNegotiation.selected'); })->start(); ``` -------------------------------- ### Client-Side Subprotocol Negotiation Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/SubprotocolNegotiation.md Add the SubprotocolNegotiation middleware to a client to send a list of requested subprotocols to the server. After connecting, retrieve the selected subprotocol using getMeta. ```php $client->addMiddleware(new WebSocket\Middleware\SubprotocolNegotiation([ 'subproto-1', 'subproto-2', 'subproto-3', ])); $client->connect(); $selected_subprotocol = $this->client->getMeta('subprotocolNegotiation.selected'); ``` -------------------------------- ### Configuration: Logger Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Set a PSR-4 compatible logger for the connection. ```APIDOC ## Configuration: Logger ### Description Set a PSR-4 compatible logger for the connection. ### Method - `setLogger(Psr\Log\LoggerInterface $logger)`: Adds a PSR-4 compatible logger to the connection. ### Request Example ```php $connection->setLogger(Psr\Log\LoggerInterface $logger); ``` ``` -------------------------------- ### WebSocket\Trait\ConfigurationTrait::setConfiguration Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Sets the configuration object. ```APIDOC ## WebSocket\Trait\ConfigurationTrait::setConfiguration ### Description Sets the configuration object. ### Method public ### Signature setConfiguration(WebSocket\Configuration $configuration): self ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - self: The instance of the class. #### Response Example None ``` -------------------------------- ### Sending Various Message Types via Connection (Convenience Methods) Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Utilizes convenience methods on the Connection instance to send Text, Binary, Ping, Pong, and Close messages to a client. ```php $connection->text("Server sends a message"); $connection->binary($binary); $connection->ping("My ping"); $connection->pong("My pong"); $connection->close(1000, "Closing now"); ``` -------------------------------- ### Running WebSocket Client with Fibers Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Examples.md Use Fibers to manage coroutines and switch code context when running the WebSocket client. Ensure the timeout is set to a low value for responsiveness. ```php use Fiber; use WebSocket\Client; use WebSocket\Connection; use WebSocket\Message\Text; use WebSocket\Middleware\{ CloseHandler, PingResponder, }; // Create client $client = new Client("wss://echo.websocket.org/"); $client // Add standard middlewares ->addMiddleware(new CloseHandler()) ->addMiddleware(new PingResponder()) // Timeout should have a pretty low value ->setTimeout(1) ->onText(function (Client $client, Connection $connection, Text $message) { echo "> Received '{$message->getContent()}' [opcode: {$message->getOpcode()}]\n"; }) ->onTick(function () { Fiber::suspend(); // Suspend after each listener loop }) ; // Create array with fibers $fibres = [ 'listener' => new Fiber(function () use ($client) { $client->start(); // Start listener }), 'sender' => new Fiber(function () use ($client) { while ($client->isWritable()) { if (rand(0, 10) == 0) { // Random close $message = $client->close(); // Send a message echo "< Sent '{$message->getContent()}' [opcode: {$message->getOpcode()}]\n"; return; // Return from function to terminate } $message = $client->text("My message " . rand(1000, 9999)); // Send a message echo "< Sent '{$message->getContent()}' [opcode: {$message->getOpcode()}]\n"; Fiber::suspend(); // Suspend after each sent mesage } }), // + Any other Fiber you need to run ]; // Switching context by looping Fibers do { foreach ($fibres as $name => $fiber) { echo sprintf( "Running fiber: %s [started: %s, running: %s, suspended: %s, terminated: %s]\n", $name, json_encode($fiber->isStarted()), json_encode($fiber->isRunning()), json_encode($fiber->isSuspended()), json_encode($fiber->isTerminated()), ); if ($fiber->isRunning() || $fiber->isTerminated()) { continue; } if ($fiber->isSuspended()) { $fiber->resume(); // Resume if suspended continue; } $fiber->start(); // Start if not started } } while ($client->isRunning()); ``` -------------------------------- ### Compressor Interface Methods Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Defines methods for compressing and decompressing WebSocket messages, and retrieving configuration and header values. ```php public method compress(WebSocket\Message\Binary|WebSocket\Message\Text $message, object $configuration): WebSocket\Message\Binary|WebSocket\Message\Text; public method decompress(WebSocket\Message\Binary|WebSocket\Message\Text $message, object $configuration): WebSocket\Message\Binary|WebSocket\Message\Text; public method getConfiguration(string $element, bool $isServer): object; public method getRequestHeaderValue(): string; public method getResponseHeaderValue(object $configuration): string; ``` -------------------------------- ### WebSocket\Configuration Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Manages the configuration settings for WebSocket connections, including logger, context, timeout, frame size, and persistence. ```APIDOC ## WebSocket\Configuration ### Description Manages the configuration settings for WebSocket connections, including logger, context, timeout, frame size, and persistence. ### Methods - `__construct(Psr\Log\LoggerInterface|null $logger = null, Phrity\Net\Context|null $context = null, int|float|null $timeout = null, int|null $frameSize = null, bool|null $persistent = null, int|null $maxConnections = null)`: Constructor for the Configuration class. - `__toString(): string`: Returns a string representation of the configuration. - `getContext(): Phrity\Net\Context`: Retrieves the network context. - `getFrameSize(): int`: Retrieves the frame size setting. - `getLogger(): Psr\Log\LoggerInterface`: Retrieves the logger instance. - `getMaxConnections(): int|null`: Retrieves the maximum number of connections allowed. - `getTimeout(): int|float`: Retrieves the timeout setting. - `isPersistent(): bool`: Checks if the persistent connection mode is enabled. - `setContext(Phrity\Net\Context $context): void`: Sets the network context. - `setFrameSize(int $frameSize): void`: Sets the frame size. - `setLogger(Psr\Log\LoggerInterface $logger): void`: Sets the logger instance. - `setMaxConnections(int|null $maxConnections): void`: Sets the maximum number of connections. - `setPersistent(bool $persistent): void`: Sets the persistent connection mode. ``` -------------------------------- ### Client Sending and Receiving Messages Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Message.md Demonstrates how a WebSocket client sends a Text message and receives a message from the server. It also shows how to listen for incoming Text messages. ```php // Client sending Message to server $client->send(new WebSocket\Message\Text("Some text to be sent")); // Client receiving Message from server $message = $client->receive(); // Client listen to messages of Text type $client->onText(function ($client, $connection, $message) { // Client sending Message to server $client->send(new WebSocket\Message\Text("Some text to be sent")); }); ``` -------------------------------- ### WebSocket\Middleware\CompressionExtension\CompressorInterface Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Interface for compression extensions, defining methods for construction, compression, decompression, configuration retrieval, and header value generation. ```APIDOC ## Interface WebSocket\Middleware\CompressionExtension\CompressorInterface ### Description Interface for compression extensions, defining methods for construction, compression, decompression, configuration retrieval, and header value generation. ### Methods - `__construct(WebSocket\Middleware\CompressionExtension\CompressorInterface $compressors)`: Constructor for the compression extension. - `processHttpIncoming(WebSocket\Middleware\ProcessHttpStack $stack, WebSocket\Connection $connection): Psr\Http\Message\MessageInterface`: Processes incoming HTTP messages. - `processHttpOutgoing(WebSocket\Middleware\ProcessHttpStack $stack, WebSocket\Connection $connection, Psr\Http\Message\MessageInterface $message): Psr\Http\Message\MessageInterface`: Processes outgoing HTTP messages. - `processIncoming(WebSocket\Middleware\ProcessStack $stack, WebSocket\Connection $connection): WebSocket\Message\Message`: Processes incoming messages. - `processOutgoing(WebSocket\Middleware\ProcessStack $stack, WebSocket\Connection $connection, WebSocket\Message\Message $message): WebSocket\Message\Message`: Processes outgoing messages. - `setLogger(Psr\Log\LoggerInterface $logger): void`: Sets the logger for the middleware. ``` -------------------------------- ### Adding Middlewares to WebSocket Server Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Server.md Configures a WebSocket server by adding CloseHandler and PingResponder middlewares for standard protocol operations. ```php $server = new WebSocket\Server(); $server // Add CloseHandler middleware ->addMiddleware(new WebSocket\Middleware\CloseHandler()) // Add PingResponder middleware ->addMiddleware(new WebSocket\Middleware\PingResponder()); ``` -------------------------------- ### Configure Maximum Redirects for FollowRedirect Middleware Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/FollowRedirect.md Instantiate the FollowRedirect middleware with a custom maximum number of redirects. This prevents infinite redirect loops and controls how many redirects the client will follow. ```php // Allow 20 redirects $client->addMiddleware(new WebSocket\Middleware\FollowRedirect(20); ``` -------------------------------- ### WebSocket\Middleware\CompressionExtension Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md A middleware for handling compression extensions in WebSocket communication. ```APIDOC ## WebSocket\Middleware\CompressionExtension ### Description Handles compression extensions for WebSocket messages during HTTP outgoing and incoming, as well as general incoming and outgoing message processing. ### Methods - **setLogger**(Psr\Log\LoggerInterface $logger): void - Sets a logger for the middleware. ``` -------------------------------- ### Enforcing Subprotocol Negotiation (Server) Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Middleware/SubprotocolNegotiation.md Configure the SubprotocolNegotiation middleware on the server with the second parameter set to true to enforce negotiation. A failed negotiation will cause the server to respond with a '426 Upgrade Required' HTTP error status. ```php $server->addMiddleware(new WebSocket\Middleware\SubprotocolNegotiation([ 'subproto-1', 'subproto-2', 'subproto-3', ], true)); ``` -------------------------------- ### Configuring WebSocket Connection Logger Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Connection.md Set a PSR-4 compatible logger for the WebSocket connection to record events. ```php $connection->setLogger(Psr\Log\LoggerInterface $logger); ``` -------------------------------- ### WebSocket Frame Handling Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Methods for creating, parsing, and managing WebSocket frames. ```APIDOC ## WebSocket\Frame\Frame ### Description Represents a single WebSocket frame, allowing manipulation of its opcode, payload, and flags. ### Methods - **__construct(string $opcode, string $payload, bool $final, bool $rsv1 = false, bool $rsv2 = false, bool $rsv3 = false)** Constructs a new Frame object. - **__toString(): string** Returns a string representation of the frame. - **getOpcode(): string** Gets the opcode of the frame. - **getPayload(): string** Gets the payload of the frame. - **getPayloadLength(): int** Gets the length of the frame's payload. - **getRsv1(): bool** Gets the state of the RSV1 bit. - **getRsv2(): bool** Gets the state of the RSV2 bit. - **getRsv3(): bool** Gets the state of the RSV3 bit. - **isContinuation(): bool** Checks if this frame is a continuation frame. - **isFinal(): bool** Checks if this is the final frame in a sequence. - **setRsv1(bool $rsv1): void** Sets the RSV1 bit. ## WebSocket\Frame\FrameHandler ### Description Handles the process of pulling and pushing WebSocket frames to and from a socket stream. ### Methods - **__construct(Phrity\Net\SocketStream $stream, bool $pushMasked, bool $pullMaskedRequired, WebSocket\Configuration|null $configuration = null)** Constructs a FrameHandler. - **pull(): WebSocket\Frame\Frame** Pulls a complete WebSocket frame from the stream. - **push(WebSocket\Frame\Frame $frame): int** Pushes a WebSocket frame onto the stream and returns the number of bytes written. - **setLogger(Psr\Log\LoggerInterface $logger): void** Sets a logger for the FrameHandler. ``` -------------------------------- ### Registering Error Listener Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Listener.md Set up a listener to handle resolvable errors that occur within the WebSocket connection. The connection object may be null, and the caught exception is provided as an argument. ```php $client_or_server // When a resolvable error occurs, this listener will be called ->onError(function (WebSocket\Client|WebSocket\Server $client_or_server, WebSocket\Connection|null $connection, WebSocket\Exception\ExceptionInterface $exception) { // Act on exception }) ; ``` -------------------------------- ### Check Code Standard Adherence Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Contributing.md Run this Make command to verify that the code adheres to PSR-1 and PSR-12 coding standards. ```bash # Check code standard adherence make cs ``` -------------------------------- ### WebSocket\Middleware\FollowRedirect Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Middleware to handle HTTP redirects for WebSocket connections, with a configurable limit. ```APIDOC ## Class WebSocket\Middleware\FollowRedirect ### Description Middleware to handle HTTP redirects for WebSocket connections, with a configurable limit. ### Methods - `__construct(int $limit = 10)`: Constructor for the FollowRedirect middleware. - `processHttpIncoming(WebSocket\Middleware\ProcessHttpStack $stack, WebSocket\Connection $connection): Psr\Http\Message\MessageInterface`: Processes incoming HTTP messages to handle redirects. - `setLogger(Psr\Log\LoggerInterface $logger): void`: Sets the logger for the middleware. ``` -------------------------------- ### WebSocket\Runtime\Runner Methods Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Manages the execution and handling of streams within the WebSocket runtime. ```APIDOC ## WebSocket\Runtime\Runner ### Description Manages the lifecycle and event handling for streams in the WebSocket runtime environment. ### Methods - **__construct(Phrity\Net\StreamFactory $streamFactory)**: Initializes the runner with a stream factory. - **attach(Phrity\Net\StreamContainerInterface $streamContainer, Closure $onSelect): void**: Attaches a stream container and a callback for stream selection. - **detach(string $identity): void**: Detaches a stream container by its identity. - **handle(int|float $timeout): void**: Handles stream events with a specified timeout. - **select(int|float $timeout): Phrity\Net\StreamCollection**: Selects streams that are ready for I/O operations with a timeout. ``` -------------------------------- ### Runner Event Loop Methods Source: https://github.com/sirn-se/websocket-php/blob/v3.7-main/docs/Class_Synopsis.md Manages the event loop for handling streams, including attaching, detaching, selecting, and handling events. ```php public method attach(Phrity\Net\StreamContainerInterface $streamContainer, Closure $onSelect): void; public method detach(string $identity): void; public method handle(int|float $timeout): void; public method select(int|float $timeout): Phrity\Net\StreamCollection; ```