PHPackages                             phpdot/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. phpdot/realtime

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

phpdot/realtime
===============

Real-time WebSocket engine — rooms, channels, presence, broadcast. Transport-agnostic: depends only on phpdot/contracts, never a concrete server.

v0.2.0(2w ago)001MITPHPPHP &gt;=8.5

Since Jul 18Pushed 2w agoCompare

[ Source](https://github.com/phpdot/realtime)[ Packagist](https://packagist.org/packages/phpdot/realtime)[ RSS](/packages/phpdot-realtime/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (14)Versions (3)Used By (1)

phpdot/realtime
===============

[](#phpdotrealtime)

A real-time WebSocket engine for PHPdot — **rooms, channels, presence, and broadcast** over plain JSON frames, with a Socket.IO-style `Hub`/`Socket` API and an explicit-targeting broadcast operator. It is transport-agnostic: it reaches clients only through `PHPdot\Contracts\Server\ConnectionSenderInterface`, so it never names a concrete server. A pluggable adapter backs membership and presence — a `Swoole\Table` for a single node, or Redis for a multi-node cluster.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Architecture](#architecture)
- [Testing](#testing)
- [License](#license)

Requirements
------------

[](#requirements)

RequirementConstraintPHP`>= 8.5``ext-swoole``>= 6.2``phpdot/contracts``^0.2``psr/http-message``^2.0`Installation
------------

[](#installation)

```
composer require phpdot/realtime
```

Usage
-----

[](#usage)

`realtime` carries no DI attributes on purpose — you bind the seam in your application. The `Hub` reaches clients through `ConnectionSenderInterface` (implemented by your server's connection registry), and the `Adapter`/`Hub` must be resolved **once at bootstrap**, before the server forks workers, because `Swoole\Table` is shared memory only when created pre-fork:

```
use PHPdot\Contracts\Server\ConnectionSenderInterface;
use PHPdot\Realtime\Adapter\TableAdapter;
use PHPdot\Realtime\Contract\Adapter;
use PHPdot\Realtime\Hub;

ConnectionSenderInterface::class => fn ($c) => $c->get(ConnectionRegistry::class),
Adapter::class => fn ($c) => new TableAdapter($c->get(ConnectionSenderInterface::class)),
Hub::class     => fn ($c) => new Hub($c->get(Adapter::class), $c->get(ConnectionSenderInterface::class)),
```

The `Hub` is the `io`: it owns the fd → `Socket` map, `onConnection`, `emit`, `to`/`except`/`direct`, `room()`, and the transport lifecycle (`handleOpen` / `handleMessage` / `handleClose`). Each `Socket`exposes the per-connection API (`emit`, `broadcast`, `join`/`leave`, `on`, `disconnect`), and `RoomFacade` answers presence queries (`members()`, `count()`).

### Single node vs cluster

[](#single-node-vs-cluster)

`TableAdapter` coordinates rooms and presence across the workers of one instance through a `Swoole\Table`. For several instances behind a load balancer, bind `RedisAdapter` instead: every node shares membership through Redis and relays broadcasts over pub/sub. `RedisSubscriber` runs the blocking SUBSCRIBE loop on a dedicated connection, and `Maintenance\ClusterMaintenance` heartbeats each node and reaps the membership of dead peers so leaked rooms and presence are reclaimed automatically.

Architecture
------------

[](#architecture)

Application and transport callbacks drive the `Hub`, which resolves `Socket`s and fans events out through the `Adapter`. The adapter is the only thing that touches storage — a `Swoole\Table` (single node) or Redis (cluster) — and the `Hub` pushes frames to clients solely through `ConnectionSenderInterface`, so the engine never depends on a concrete server.

 ```
graph TD
    APP["Application + transport callbacksonConnection / handleOpen / handleMessage / handleClose"]
    HUB["Hub (io)fd → Socket map, emit, to/except/direct, room()"]
    SOCKET["Socket + BroadcastOperator + RoomFacadeper-connection API, explicit targeting, presence"]
    ADAPTER["Contract AdapterTableAdapter (single node) / RedisAdapter (cluster)"]
    SENDER["Contracts Server ConnectionSenderInterfacethe only path to a client — no concrete server"]

    APP --> HUB
    HUB --> SOCKET
    HUB --> ADAPTER
    HUB --> SENDER
    ADAPTER --> SENDER
```

      Loading Testing
-------

[](#testing)

```
composer install
composer test        # PHPUnit
composer analyse     # PHPStan, level max + strict rules
composer cs-check    # PHP-CS-Fixer
composer check       # All three
```

License
-------

[](#license)

MIT.

**This repository is a read-only mirror**, generated by CI from [phpdot/monorepo](https://github.com/phpdot/monorepo). [Pull requests](https://github.com/phpdot/monorepo/pulls)and [issues](https://github.com/phpdot/monorepo/issues) belong in the monorepo.

###  Health Score

38

—

LowBetter than 82% of packages

Maintenance97

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

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

Every ~32 days

Total

2

Last Release

14d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e82421bda4b5d6ba9a47ba6d88caca060dcd0d1a2862f351f3a97657385db0?d=identicon)[phpdot](/maintainers/phpdot)

---

Top Contributors

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

---

Tags

websocketswoolerealtimechannelsBroadcastroomspresence

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpdot-realtime/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.6k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.4k567.5M2.9k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.1k1.0M59](/packages/neuron-core-neuron-ai)[phrity/websocket

WebSocket client and server

2175.5M48](/packages/phrity-websocket)[tempest/framework

The PHP framework that gets out of your way.

2.3k42.4k21](/packages/tempest-framework)[hyperf/hyperf

A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

6.9k3.5k2](/packages/hyperf-hyperf)

PHPackages © 2026

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