Download the PHP package ez-php/broadcast without Composer
On this page you can find all versions of the php package ez-php/broadcast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ez-php/broadcast
More information about ez-php/broadcast
Files in ez-php/broadcast
Package broadcast
Short Description Real-time event broadcasting for ez-php — pluggable drivers (Null, Log, Array), SSE response helpers, and a static Broadcast facade
License MIT
Homepage https://github.com/ez-php/broadcast
Informations about the package broadcast
ez-php/broadcast
Real-time event broadcasting for ez-php applications. Publish events to named channels via a pluggable driver (Null, Log, Array, Redis) and stream them to connected clients using Server-Sent Events (SSE).
Installation
Quick Start
Register the provider in provider/modules.php:
Add configuration to config/broadcast.php:
Publish an event from anywhere:
Broadcastable Events
Implement BroadcastableInterface to make any event class broadcastable:
Dispatch via the facade:
Drivers
| Driver | BROADCAST_DRIVER |
Description |
|---|---|---|
| Null | null |
Silently discards all events (default) |
| Log | log |
Writes a summary to a log file or via error_log() |
| Array | array |
Stores events in memory — designed for testing |
| Redis | redis |
Publishes to Redis Pub/Sub channels via ext-redis |
Log Driver
When BROADCAST_LOG_PATH is empty, events are written via error_log().
Redis Driver
Publishes events to Redis Pub/Sub channels via PHP's ext-redis extension. Subscribers (SSE proxy, WebSocket gateway) must be running separately — Redis Pub/Sub is fire-and-forget.
Array Driver (for Testing)
Server-Sent Events (SSE)
Server-Sent Events are an HTTP wire format and live in ez-php/http since 2.0:
EzPhp\Http\Sse\SseEvent and StreamedResponse::sse(). Return the response from a
controller — it travels through middleware (auth, CORS) like any other response:
The 1.x SseStream / SseResponse classes and the $response->emit(); exit; pattern
were removed: they bypassed middleware and terminate(). See
ez-php/docs/upgrade-1.x-to-2.0.md.
Static Facade
Broadcast is a static facade backed by a Broadcaster singleton:
| Method | Description |
|---|---|
Broadcast::event(BroadcastableInterface) |
Publish via broadcastOn(), broadcastAs(), broadcastWith() |
Broadcast::to(string $channel, string $event, array $payload) |
Publish directly |
Broadcast::setBroadcaster(Broadcaster) |
Wire the singleton (done by BroadcastServiceProvider) |
Broadcast::resetBroadcaster() |
Reset to null — call in test tearDown() |
Throws RuntimeException if called before setBroadcaster().
Custom Driver
Implement BroadcastDriverInterface to add a custom backend:
Bind it in a service provider:
Client-Side Usage (JavaScript)
The browser's built-in EventSource API consumes SSE streams with no extra library required.
Basic subscription
Authenticated streams
SSE uses standard HTTP — pass credentials via a cookie or a query-parameter token (headers are not configurable in the browser EventSource API):
On the PHP side, validate $_GET['token'] in the SSE controller before opening the stream.
Multiple event types on one connection
Exceptions
BroadcastException (extends RuntimeException) is the base exception for this package. Broadcast::event() / Broadcast::to() throw RuntimeException if called before the broadcaster is set.