New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

webpatser/resonate

Fiber-based WebSocket server for PHP 8.6: a drop-in replacement for Laravel Reverb, built on fledge-fiber
1,007
Install
composer require webpatser/resonate
Latest Version:v1.7.1
PHP:^8.6
Laravel:13
License:MIT
Last Updated:Nov 27, 2026
Links: GitHub  ·  Packagist
Maintainer: webpatser

Resonate

Fiber-based drop-in replacement for Laravel Reverb, built on webpatser/fledge-fiber and PHP 8.6.

Why

Reverb is already async, but it pulls in its own ReactPHP / Ratchet / clue-redis stack. Resonate consolidates the runtime onto Fledge: webpatser/fledge-loop + webpatser/fledge-fiber, the same async stack that powers webpatser/torque, webpatser/laravel-fiber, and webpatser/laravel-resp3-cache. The wins are practical:

  • PHP 8.6 only. No polyfills, no version_compare, native URI parser, native array_all / array_any.
  • One async runtime per app. Fledge's HTTP server gives HTTP/2 and shares the loop with the rest of your async work, with no second event loop competing for the request.
  • Fiber ergonomics. Channel auth, application providers, and pub/sub callbacks read like synchronous code but yield on I/O. Custom auth backends can hit a database or HTTP API without blocking the tick.

The wire protocol, REST API, and config schema are byte-compatible with Laravel Reverb.

Fledge's async layer started as a port of amphp and its event loop as a port of Revolt, both MIT licensed. Those projects showed how far fibers can take PHP, and Fledge builds on that work. Fledge has since gone its own way: PHP 8.6 only, shaped around Laravel, and maintained independently, so it does not track either project.

Install (fresh app)

composer require webpatser/resonate
php artisan resonate:install
php artisan resonate:start

Install (swap from laravel/reverb)

composer remove laravel/reverb
composer require webpatser/resonate

That's it. Nothing else changes:

  • Same config/reverb.php. Resonate reads the existing file.
  • New artisan commands: resonate:start, resonate:restart, resonate:reload, resonate:install. Update supervisor / systemd / Docker entrypoints accordingly.
  • Same laravel:reverb:restart cache key. Running servers restart on the same signal.
  • Same Pusher wire protocol (byte-exact JSON framing) and the same Pusher-compatible REST API.
  • Supervisor / systemd / Docker configs stay as-is.
  • Front-end Echo and pusher-js configs stay as-is.

Zero-downtime reload

resonate:restart is the legacy hard restart: it sets the laravel:reverb:restart cache key, the running server picks it up within 5 seconds, calls stop(), and your supervisor respawns it. WebSocket connections drop; the listener is gone for the 0-5 second window between exit and respawn. Fine for development, rough for production deploys.

resonate:reload is the production path. The listener is bound with SO_REUSEPORT so the new process can hold the port while the old one drains. On Linux, connections still waiting in the old listener's accept backlog when it closes are reset unless net.ipv4.tcp_migrate_req=1 is set, which hands them to the new listener.

# Default: spawn a replacement, wait for /up, then drain the old PID.
php artisan resonate:reload

# Drain only (for systemd ExecReload=, Kubernetes preStop, Supervisor).
php artisan resonate:reload --drain

Tune the drain window with REVERB_DRAIN_TIMEOUT (default 30 seconds). Existing WebSocket clients stay connected to the old process until they disconnect naturally or the timeout fires. --term-timeout (default 5 seconds) bounds the wait for the old process to exit after SIGTERM; the reload fails rather than reporting success if it is still alive.

Under Supervisor, resonate:reload automatically becomes drain-only: the server records at start whether it runs under Supervisor, and there is then no overlap, so the port is briefly unserved. The Supervisor program needs autorestart=true: with the default autorestart=unexpected, a clean exit 0 after the drain is not restarted and the server stays down.

GET /up returns the PID of the process that answered alongside health, so a probe can tell the replacement apart from the outgoing server while both hold the port.

Runtime files

resonate:start writes two files into storage/:

File Contents
resonate.pid The server PID, written once the listening sockets are bound.
resonate.json The PID, the effective host, port and path the server was started with, and the supervised key (whether it runs under Supervisor).

resonate:reload reads the metadata file so a replacement inherits the CLI overrides the running server was started with, rather than falling back to config. Metadata belonging to another PID is ignored.

A second resonate:start fails while the PID file names a live process, since SO_REUSEPORT would otherwise let it bind the same port and split the node into two processes with separate channel state. Pass --force to start anyway; resonate:reload passes it during a swap.

Event loop and connection count

resonate:start runs as one long-lived process. Before it builds the server it installs the event loop driver named by servers.reverb.event_loop, which reads FLEDGE_EVENT_LOOP:

FLEDGE_EVENT_LOOP Driver
auto (default, also when unset) kqueue (macOS, BSD) or epoll (Linux) through PHP's Io\Poll; stream_select where neither exists
poll kqueue or epoll; the server refuses to start when neither is available
select stream_select, the rollback

With the poll driver a node is no longer capped at about a thousand connections: stream_select cannot watch a descriptor above FD_SETSIZE (usually 1024), kqueue and epoll have no such ceiling. Every connection costs one descriptor, so the limit becomes the process's open file limit. Raise it for the server process, for example LimitNOFILE=65536 in a systemd unit or ulimit -n 65536 in the script that starts it. Any other value of FLEDGE_EVENT_LOOP makes resonate:start refuse to boot. FLEDGE_EVENT_LOOP in the process environment wins over the setting, so FLEDGE_EVENT_LOOP=select rolls back even with a cached config (config:cache); the command logs one line when the two differ.

At startup resonate:start checks the soft open file limit against what it needs: the connection_limit setting, or 4096 connections when it is unlimited, plus 256 descriptors for the listener, Redis, the database and logs. A lower soft limit is raised as far as the hard limit allows (up to 65536) and the command says so; when the hard limit is too low it prints a warning with the numbers. Raise the hard limit for large nodes.

TCP_NODELAY is set on the listening socket, so every accepted connection, TLS included, sends small frames at once. TCP keep-alive is off by default, since the Pusher protocol already pings quiet clients (ping_interval) and prunes the ones that stop answering; set REVERB_TCP_KEEPALIVE=true (operating system timings) or a number of idle seconds (REVERB_TCP_KEEPALIVE=60) when a NAT or firewall drops idle flows sooner.

SIGTERM and SIGINT stop the server gracefully: the listener closes, every client gets a 1001 close frame, the PID file is removed and the process exits 0. SIGUSR2 drains instead (see above).

Resource limits

Defaults are set for a shared, multi-tenant process. Set any of these to 0 to disable the check.

Key (under servers.reverb) Environment variable Default What it bounds
max_channel_name_length REVERB_MAX_CHANNEL_NAME_LENGTH 255 Length of a channel name a client may subscribe to. An over-long subscribe is rejected with pusher:subscription_error (InvalidChannelName, status 4300) naming the channel; the connection stays open. Pusher itself caps names at 164 characters.
validate_channel_names REVERB_VALIDATE_CHANNEL_NAMES true Restricts channel names to Pusher's charset A-Z a-z 0-9 _ - = @ , . ; (plus the #server-to-user- prefix) on subscribe, unsubscribe and the REST channel and event endpoints. Set to false to disable (a boolean, not a 0 limit). Violations get pusher code 4200 over the socket and HTTP 400/422 over REST.
max_subscriptions_per_connection REVERB_MAX_SUBSCRIPTIONS_PER_CONNECTION 250 Distinct channels one connection may hold. An over-cap subscribe is rejected with pusher:subscription_error (LimitReached, status 4300) naming the channel; the connection and its existing subscriptions stay intact.
connection_limit REVERB_CONNECTION_LIMIT unlimited Total open TCP connections per node (WebSocket upgrades and HTTP API calls alike), a transport-level cap applied before any Resonate code runs. Independent of the per-app max_connections. A connection over the cap is closed without a Pusher error. Unlike the other rows, this one defaults to unlimited: leaving it unset or null (or setting '' or 0) keeps it unlimited, as in Reverb.
connection_limit_per_ip REVERB_CONNECTION_LIMIT_PER_IP unlimited Open connections per TCP peer address (loopback is exempt). Same semantics as connection_limit; behind a reverse proxy every client shares the proxy's address. See SECURITY.md.
max_outbound_queue_size REVERB_MAX_OUTBOUND_QUEUE_SIZE 1000 Messages that may wait on one connection. Exceeding it closes the connection with WebSocket code 1013.
scaling.max_queued_messages REVERB_SCALING_MAX_QUEUED_MESSAGES 10000 Inbound pub/sub envelopes waiting to be handled. Envelopes arriving while the queue is full are dropped and logged.

Trusted proxies

servers.reverb.trusted_proxies (REVERB_TRUSTED_PROXIES, comma-separated, empty by default) lists the reverse proxies or load balancers, as CIDR ranges or bare addresses, whose X-Forwarded-For header is believed. A connection whose TCP peer is in the list is rate limited as the right-most X-Forwarded-For address that is not itself a trusted proxy; from any other peer the header is ignored. Without it, every client behind a proxy shares the proxy's message rate-limit quota. An entry that is not an IP address or CIDR range makes resonate:start refuse to boot.

REVERB_TRUSTED_PROXIES=10.0.0.0/8,fd00::/8

Outbound queues

Every connection owns an outbound queue drained by a single writer fiber. send() queues and returns, so a client that stops reading its socket suspends only its own writer instead of stalling the channel fan-out and whatever issued the broadcast. One writer per connection keeps frames in the order they were queued.

The bound exists because unbounded buffering trades a stall for memory exhaustion. Budget for it as the bound multiplied by your average payload multiplied by the number of connections that can fall behind at once. A connection closed with 1013 reconnects and resubscribes on its own, which is standard Pusher client behaviour.

Message size

apps.apps[].max_message_size (default 10_000 bytes) is enforced per application. The application is known during the handshake, so each connection's RFC 6455 parser carries its own application's limit and an oversized frame is refused on its header with close code 1009, before a payload byte is buffered. The protocol layer re-checks the assembled message and rejects it with pusher code 4019.

The server-wide limit is now the smallest limit configured across your applications, and it governs only an upgrade whose app key resolves to no application. Such a connection is closed with pusher code 4001 as soon as the handler takes over.

Horizontal scaling

Set REVERB_SCALING_ENABLED=true along with your REDIS_* variables. Multiple Resonate instances coordinate via Redis pub/sub on fledge-fiber's async Redis client; message, terminate, and metrics events propagate across nodes.

Resonate uses a pure JSON envelope for cross-node messages, with no serialize() on the wire. This means a cluster cannot run mixed Resonate and laravel/reverb nodes; migration is all-at-once.

Differences from Reverb under scaling

  • A presence channel's user_count counts distinct users across nodes; Reverb sums each node's count. During a rolling deploy from an older release, nodes on the old build still add up counts.
  • GET /apps/{app}/channels/{channel}/users returns 400 for a non-presence name where Reverb returns 404. The answer waits for the other nodes for up to the collection window, and a node that does not answer in time is left out.
  • The HTTP API signature check strips the --path prefix, whether it comes from --path or from config.

Server-side plugins

Resonate is a product-agnostic Pusher relay, but the fiber runtime makes it a natural host for stateful, server-side application logic - periodic timers, custom message types, connection bookkeeping - without a second process. The plugin API exposes that without coupling Resonate to any one product.

A plugin implements ServerPlugin plus any of three capability interfaces:

  • MessageInterceptor - onMessage(Connection, array $event): MessageDisposition. Runs before the standard pusher: / client-* routing. Return Handled or Rejected to consume a custom event type, or Relay (the default for traffic you don't own) to leave ordinary Pusher messages untouched.
  • ConnectionLifecycle - onOpen / onClose / onSubscribe / onUnsubscribe. Observe connection transitions to maintain your own registries.
  • TickScheduler - ticks() returns [{interval, callback}]. Each callback is scheduled on the event loop inside a fiber, so async DB/Redis calls suspend the fiber rather than blocking the loop.

Plugins receive a PluginContext at boot() with sendTo(), broadcast() (scaling-aware), terminate(), unsubscribe(), joinUserChannel(), and connectionsOn(). broadcast() and connectionsOn() take an Application, an app id string, or null for the sole configured app, and the context resolves one itself via application() / applications() - so a TickScheduler callback, which has no connection to derive an app from, can still broadcast. Per-connection state lives on the Connection via setState() / state(). Register plugin classes in config/reverb.php:

'servers' => [
    'reverb' => [
        // ...
        'plugins' => [
            App\Resonate\ChatPlugin::class,
        ],
    ],
],

Plugin classes are resolved through the container (so their dependencies inject), booted once at server start, and every hook call is exception-isolated - a misbehaving plugin can never break the core connection lifecycle.

First-party plugins

A small family of plugins ships under webpatser/*. Pick the ones you need; each is opt-in, each has its own README with the full setup.

Package What it does
webpatser/resonate-roster Cluster-wide presence and channel-occupancy state in Redis. Restart-safe, self-healing, queryable from the backend without a metrics round-trip.
webpatser/resonate-webhooks Pusher-style HTTP webhooks (channel_occupied/channel_vacated, member_added/member_removed, client_event). Signed, exactly-once per cluster via the roster.
webpatser/resonate-user-cap Per-user connection cap with cluster-correct enforcement. Terminates over-cap connections with a Pusher error frame.
webpatser/resonate-token-auth Token-based subscribe auth (JWT by default, pluggable). Lets mobile and S2S clients skip /broadcasting/auth.
webpatser/resonate-delivery At-least-once message delivery within a retention window: every broadcast logged to a Redis Stream, replayed to reconnecting subscribers.
webpatser/resonate-pulse Laravel Pulse cards for the suite: roster occupancy, webhook deliveries, user-cap terminations, token-auth rejections.

A companion Laravel-side package, not a Resonate plugin, that consumes the webhooks:

Package What it does
webpatser/resonate-channel-meter Records billable and observable channel occupancy periods from resonate-webhooks events as Eloquent models in your Laravel app.

See docs/plugins.md for the same list with framing notes, plus a full setup walkthrough with a worked plugin you can build yourself.

OpenTelemetry metrics

Resonate can report its numbers through OpenTelemetry. It is off by default and needs open-telemetry/api plus a meter provider bound in the container, which webpatser/fledge-apm does when its metrics are enabled. Both are suggest entries, never requirements. Set RESONATE_OTEL_METRICS=true (servers.reverb.otel_metrics) to turn it on:

Instrument Kind, unit
resonate.connection.count observable gauge, {connection}
resonate.channel.count observable gauge, {channel}
resonate.connection.pruned observable counter, {connection}
resonate.message.received observable counter, {message}
resonate.message.sent observable counter, {message}

resonate.message.received counts every valid inbound frame that reaches the plugin layer, Pusher protocol events included, also when a later plugin consumes it. resonate.message.sent counts one per receiving connection, so a broadcast to 500 subscribers adds 500; it includes protocol replies such as pong, subscription_succeeded and error frames, and excludes the error frame sent when a connection is rejected for an unknown app key. The message paths only bump an in-memory integer per app; the meter reads the totals when it collects, and the gauges read the channel manager per app at that moment. Instruments are created when the server boots its plugins, so only the resonate:start process reports.

With several Resonate servers, each reports its own local counts under its own service.instance.id. Connections and frames sum across instances; a channel open on two servers counts once per server in resonate.channel.count.

The only attribute is resonate.app.id; channel names, connection ids, socket ids, user ids and event names are never attributes. With the flag off, or when either dependency is missing, the plugin is not registered and the message path does no extra work.

Requirements

  • PHP ^8.6
  • Laravel ^13.0

PHP version policy

This package supports only the latest stable PHP release. When a new PHP version is released, the next release of this package requires it and support for the previous PHP version ends. Currently: PHP 8.6.

Optional integrations:

  • laravel/pulse: Resonate registers the reverb.connections and reverb.messages Livewire dashboard components automatically.
  • laravel/telescope: entry storage for inspecting connections, channels, and messages.

Acknowledgements

Resonate is a clean-room port of laravel/reverb (MIT, © Taylor Otwell, Joe Dixon). Several files (notably the Pusher protocol layer and the Pulse dashboard cards) are direct ports of Reverb's MIT-licensed code. See LICENSE.md for the full attribution.

License

MIT. See LICENSE.md.

Related Packages

gramercytech/laravel-claim-check

Bypass Pusher's 10KB broadcast payload limit via the claim-check pattern. Oversi...

28,515 0
techies-africa/laravel-reverb-ui

A premium real-time telemetry dashboard for Laravel Reverb.

2,704 25
webpatser/torque

Coroutine-based queue worker for Laravel: N jobs per process via PHP Fibers and...

1,271 3
libxa/framework

LibxaFrame core framework — Foundation, Router, Atlas ORM, Blade-X, Reactive, Mo...

450 0
siberfx/message-bus

A Symfony Messenger inspired message bus for Laravel: buses, middleware, transpo...

43 0

Version History

Version Released PHP Laravel License
v1.7.1 ^8.6 ^13.0 MIT
v1.7.0 ^8.6 ^13.0 MIT
v1.6.0 ^8.6 ^13.0 MIT
v1.5.0 ^8.6 ^13.0 MIT
v1.4.0 ^8.6 ^13.0 MIT