Skip to content

WebSockets

WebSockets works pretty much the same way as Kafka out of the box.

Listening

This works the exact same way as the HTTP controllers. Use the WebSocketListener to register your handler for auto-discovery.

php
#[WebSocketListener]
class OrderListener
{
    #[MessageSub]
    public function onMessage(SpanWebSocket $span)
    {
        $span->getConnection()->send('custom payload');
    }
}

Broadcasting

As with Kafka, the client implementation is auto-generated by the framework. This also includes IPC routing of messages. Since WebSockets are open connections, sending a payload to a specific client needs to be sent from the server the connection is open on. Sugoi handles this automatically in the background out of the box with IPC messaging through Sugoi Chumon.

php
#[WebSocketClient]
interface WsClientTest
{
    #[MessagePub]
    public function publish(string $payload);
}

Configuration

yaml
sugoi:
    ws:
        address: 0.0.0.0
        port: 3030