webpatser/resonate-roster v1.2.0. Resonate keeps presence membership in process memory, per node. It is lost on a restart or reload, and it is not shared across nodes: with scaling enabled, Redis is only a pub/sub bus. The roster writes membership to Redis, so "who is online" is restart-safe, correct across nodes and readable from your Laravel app without a metrics round-trip.
How it works
A presence channel C of application A on node N is a Redis hash:
{prefix}:{A}:{C}:{N} field = socket id value = presence user id
A set per channel, {prefix}-nodes:{A}:{C}, lists the nodes that hold a hash for the channel. Each node owns only its own key, which is what makes TTL-based self-healing correct. The application id is part of the key, so two applications with the same channel name do not merge.
RedisRosterPlugin runs inside the Resonate process and reacts to three events:
| Event | What it does |
|---|---|
onSubscribe |
A connection joined a presence channel: HSET its socket id and user id into this node's key and refresh the TTL. |
onUnsubscribe |
A connection left with an explicit pusher:unsubscribe: HDEL its socket id. |
onClose |
The socket closed: HDEL its socket id from every channel recorded on its state bag. |
The hooks are the fast path. A heartbeat tick (heartbeat_interval) is authoritative: it reads the live connections from Resonate and rewrites the node's keys to match. Every key also carries a TTL, so a dead node's key expires. Data is eventually consistent within one heartbeat, and a hard node crash clears within one ttl.
Install
composer require webpatser/resonate-rosterphp artisan vendor:publish --tag=resonate-roster-config
Register the plugin in config/reverb.php:
'servers' => [ 'reverb' => [ // ... 'plugins' => [ \Webpatser\ResonateRoster\RedisRosterPlugin::class, ], ],],
Restart Resonate. Requirements: PHP 8.6+, Resonate 1.4+, and a Redis server reachable from both the Resonate process and your Laravel app.
Reading the roster
RoomRoster runs in your Laravel app and reads Redis over predis. Resolve it from the container:
use Webpatser\ResonateRoster\RoomRoster; $roster = app(RoomRoster::class); $roster->users('presence-chat.42'); // ['7', '31'] distinct user ids$roster->userCount('presence-chat.42'); // 2$roster->sockets('presence-chat.42'); // every socket id$roster->socketCount('presence-chat.42'); // 3$roster->isOnline('presence-chat.42', '7'); // true$roster->occupiedChannels(); // every channel with members
For a dashboard or sweep over every channel, snapshot() answers in one sweep plus one pipelined batch, instead of 1 + 2C sweeps for C channels:
$roster->snapshot(); // sole application$roster->snapshot('481523'); // a named one// [// 'presence-chat.42' => ['users' => ['7', '31'], 'connections' => 3],// 'updates' => ['users' => [], 'connections' => 12],// ]
Every read method takes the application id as an optional final argument:
$roster->users('presence-chat.42', '481523');$roster->isOnline('presence-chat.42', '7', '481523');$roster->occupiedChannels('481523');
Leave it out and the sole configured application is used. On a server with several applications, omitting it throws an InvalidArgumentException.
Configuration
| Key | Default | Purpose |
|---|---|---|
connection |
REDIS_* env |
The Redis server. The plugin and the reader must point at the same server and database. Per-plugin overrides use RESONATE_ROSTER_REDIS_*. |
key_prefix |
roster |
Namespace for every roster key. Avoid colons. Env: RESONATE_ROSTER_PREFIX. |
ttl |
90 |
Seconds each node's key lives, refreshed on every heartbeat. Env: RESONATE_ROSTER_TTL. |
heartbeat_interval |
30 |
Seconds between reconcile ticks. Keep it well below ttl. Env: RESONATE_ROSTER_HEARTBEAT. |
track |
presence |
presence mirrors only presence channels. all mirrors every channel type, so the roster also answers how many connections a channel has. Env: RESONATE_ROSTER_TRACK. |
scan_fallback |
true |
Read through a keyspace SCAN (needed while nodes on older releases run). Turn it off once every node runs this release to read only through the index sets. Env: RESONATE_ROSTER_SCAN_FALLBACK. |
The connection block takes Laravel's Redis connection keys and is handed to fledge-fiber verbatim: scheme (tcp, tls or rediss, unix), read_timeout, name, tcp_keepalive and the retry keys work alongside host, port, credentials and database.
Caveats
- One Redis, both sides. The plugin and
RoomRosterread the sameconnectionblock. - Presence by default. In
presencemode public and private channels are ignored. Webhooks needstrackset toall. - Distinct users.
users()deduplicates by the presenceuser_id.sockets()does not. - Not Redis Cluster safe. While
scan_fallbackis on,RoomRosterdiscovers node keys withSCAN, which on Redis Cluster walks only one node. Use a single Redis (a primary with replicas is fine). - Upgrading. Coming from a release older than 0.3.0, upgrade through 0.7.x first. 1.0 no longer reads the pre-0.3.0 key layout.