PHPackages                             octo-php/symfony-realtime - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. octo-php/symfony-realtime

ActiveLibrary[HTTP &amp; Networking](/categories/http)

octo-php/symfony-realtime
=========================

Realtime package for the Async PHP Platform — WebSocket handler, SSE event formatting/streaming, and HTTP/WS routing adapter.

v0.1.2(2mo ago)001MITPHPPHP &gt;=8.4

Since Mar 3Pushed 2mo agoCompare

[ Source](https://github.com/LaProgrammerie/octo-php-symfony-realtime)[ Packagist](https://packagist.org/packages/octo-php/symfony-realtime)[ RSS](/packages/octo-php-symfony-realtime/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (1)

octo-php/symfony-realtime
=========================

[](#octo-phpsymfony-realtime)

Package temps réel pour la plateforme async PHP — WebSocket handler, helpers SSE avancés (formatage W3C, keep-alive, reconnection), et routage HTTP/WS.

Installation
------------

[](#installation)

```
composer require octo-php/symfony-realtime
```

WebSocket
---------

[](#websocket)

### Configuration OpenSwoole

[](#configuration-openswoole)

Le support WebSocket nécessite l'activation du mode WebSocket server dans OpenSwoole. Le `RealtimeServerAdapter` remplace le handler HTTP standard pour router les requêtes :

```
use Octo\RuntimePack\ServerBootstrap;
use Octo\SymfonyRealtime\RealtimeServerAdapter;

$adapter = new RealtimeServerAdapter(
    httpHandler: $httpKernelAdapter,
    wsHandler: $myWebSocketHandler,
);

ServerBootstrap::run(
    appHandler: $adapter,
    production: true,
);
```

### WebSocketHandler

[](#websockethandler)

Implémentez l'interface `WebSocketHandler` pour gérer les connexions :

```
use Octo\SymfonyRealtime\WebSocketHandler;
use Octo\SymfonyRealtime\WebSocketContext;

final class ChatHandler implements WebSocketHandler
{
    public function onOpen(WebSocketContext $context): void
    {
        // Connexion ouverte
    }

    public function onMessage(WebSocketContext $context, string $data): void
    {
        // Frame reçue — répondre directement
        $context->send('Echo: ' . $data);
    }

    public function onClose(WebSocketContext $context): void
    {
        // Connexion fermée
    }
}
```

### WebSocketContext

[](#websocketcontext)

DTO readonly contenant les informations de connexion :

- `connectionId` — identifiant unique de la connexion
- `requestId` — request\_id propagé depuis la requête d'upgrade
- `headers` — headers de la requête d'upgrade HTTP
- `send(string $data): void` — envoyer une frame au client
- `close(): void` — fermer la connexion

### Routage HTTP / WebSocket

[](#routage-http--websocket)

Le `RealtimeServerAdapter` détecte automatiquement les requêtes d'upgrade WebSocket via les headers `Upgrade: websocket` + `Connection: Upgrade` (case-insensitive) :

- Requêtes WebSocket → déléguées au `WebSocketHandler` (frames brutes, pas de conversion HttpFoundation)
- Requêtes HTTP → déléguées au `HttpKernelAdapter` du core bridge

### Max lifetime

[](#max-lifetime)

Chaque connexion WebSocket a un max lifetime configurable :

VariableTypeDéfautDescription`OCTOP_SYMFONY_WS_MAX_LIFETIME_SECONDS`int (s)`3600`Durée maximale d'une connexion WebSocketVia le bundle :

```
octo:
    realtime:
        ws_max_lifetime_seconds: 3600
```

SSE avancé vs SSE basique
-------------------------

[](#sse-avancé-vs-sse-basique)

### SSE basique (core bridge)

[](#sse-basique-core-bridge)

Le core bridge (`octo-php/symfony-bridge`) fournit le **mécanisme de streaming** : `StreamedResponse` avec `Content-Type: text/event-stream` est automatiquement streamé via `ResponseFacade::write()` avec compression et buffering désactivés.

C'est suffisant pour des cas simples où vous formatez les événements SSE manuellement.

### SSE avancé (ce package)

[](#sse-avancé-ce-package)

Ce package fournit le **protocole SSE structuré** :

#### SseEvent

[](#sseevent)

Formatage conforme à la spécification W3C :

```
use Octo\SymfonyRealtime\SseEvent;

$event = new SseEvent(
    data: "Hello world",
    event: 'message',
    id: '42',
    retry: 3000,
);

echo $event->format();
// event: message
// data: Hello world
// id: 42
// retry: 3000
//
```

Les données multi-lignes sont automatiquement découpées en lignes `data:` séparées.

`SseEvent::parse()` permet le round-trip : `parse(format($event))` restitue les champs originaux.

#### SseStream

[](#ssestream)

Envoi d'événements SSE via `ResponseFacade::write()` avec :

- **Keep-alive périodique** : commentaire SSE `: keep-alive\n\n` envoyé toutes les 15 secondes (configurable) pour maintenir la connexion
- **Reconnection** : support du header `Last-Event-ID` pour la reconnexion client

Métriques
---------

[](#métriques)

MétriqueTypeDescription`ws_connections_active`gaugeConnexions WebSocket actives`ws_messages_received_total`counterMessages WebSocket reçus`ws_messages_sent_total`counterMessages WebSocket envoyésLicence
-------

[](#licence)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance85

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

75d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3192df86b9648428e1ad85643809f814e4a2f48279370f8bd39dc4fcacb0365?d=identicon)[laprogrammerie](/maintainers/laprogrammerie)

---

Top Contributors

[![matthieuwerner](https://avatars.githubusercontent.com/u/3184545?v=4)](https://github.com/matthieuwerner "matthieuwerner (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/octo-php-symfony-realtime/health.svg)

```
[![Health](https://phpackages.com/badges/octo-php-symfony-realtime/health.svg)](https://phpackages.com/packages/octo-php-symfony-realtime)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
