Download the PHP package maniaba/codeigniter4-sse without Composer
On this page you can find all versions of the php package maniaba/codeigniter4-sse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maniaba/codeigniter4-sse
More information about maniaba/codeigniter4-sse
Files in maniaba/codeigniter4-sse
Package codeigniter4-sse
Short Description Redis and Mercure Server-Sent Events for CodeIgniter 4
License MIT
Homepage https://github.com/maniaba/codeigniter4-sse
Informations about the package codeigniter4-sse
CodeIgniter SSE
CodeIgniter SSE is a lightweight, powerful Server-Sent Events library for CodeIgniter 4. It provides a clean, framework-native API for building real-time features with one-way event streams over HTTP.
Use it for notifications, progress updates, activity feeds, logs, live dashboards, and other event-driven UI updates. Application code publishes semantic events through one CI4 service, while the selected broker adapter handles Redis or Mercure delivery, browser streaming, and reconnect behavior.
The public API stays independent of the transport. Start with Redis for simple
deployments, switch to Mercure when long-lived browser connections should move
out of PHP, and keep the same sse()->publish(...) application code.
Requirements
- PHP 8.2 or newer
- CodeIgniter 4.7 or newer
- Redis server for the Redis adapter, or a Mercure Hub
ext-curlwhen using Mercure
Installation
Install the package:
Ensure that Redis is reachable:
The package speaks RESP2 over PHP stream sockets. It does not require PhpRedis, Predis, or another Redis client package. The PHP JSON extension is required.
Package routes, services, and Spark commands are discovered through CodeIgniter's Composer package discovery. See Installation when discovery is restricted in your application.
Quick start
Publish an event from a controller, domain service, listener, command, or queue worker:
Open the stream for one or more logical channels:
Use the included framework-independent ES module:
SseClient opens EventSource through the selected frontend adapter. When the
server broker changes, update the adapter class in the browser client.
The browser's native EventSource automatically reconnects when a connection
ends. With Redis, the package intentionally limits the PHP stream lifetime.
With Mercure, the browser streams directly from the Hub.
Channel security
The built-in authorization policy permits only channels under public.*.
Every user, tenant, order, project, or other private channel is denied until
the application provides a ChannelAuthorizerInterface implementation.
Register a matching UserResolverInterface when the application uses session,
Shield, JWT, or another authentication system. Channel names supplied by the
browser are logical names; clients never receive or control the internal Redis
prefix. In production, private SSE routes should also use application
authentication and per-user rate/concurrency filters to control open streams
and reconnect churn; filters do not replace per-channel authorization.
See Channels and authorization for the complete setup.
Configuration
Create app/Config/Sse.php when defaults need to be changed:
Redis connection details and scalar package options can be supplied through
.env. The exact options and production recommendations are documented under
Configuration.
Redis is the default broker and the easiest starting point. It uses Redis
Pub/Sub while CodeIgniter holds the browser's SSE response open from /sse.
For larger environments or applications with many concurrent users, prefer
Mercure: PHP handles short authorization and publish requests, while the Hub
owns the long-lived browser connections.
Delivery semantics
The first release deliberately uses raw Redis Pub/Sub:
- events are broadcast live;
- disconnected clients do not receive past events;
- there is no replay or guaranteed delivery;
- publisher and subscriber use separate Redis connections;
- event envelopes include an ID and schema version for future adapters.
Use a database, queue, or a future durable broker adapter when an event must
not be lost. Redis Streams and Last-Event-ID replay are outside the Pub/Sub
contract. Redis Pub/Sub is not isolated by numbered Redis databases, so every
application must use its own channelPrefix.
Mercure is available when long-lived streams should not occupy PHP workers:
Publishing remains unchanged. The /sse route becomes a short channel
authorization request that sets a topic-scoped HttpOnly JWT cookie, and the
browser client connects directly to the Hub:
Use the frontend adapter that matches the configured broker. Mercure's adapter authorizes through the package route and then opens EventSource on the Hub.
Mercure can replay retained Hub history through Last-Event-ID. See
Mercure Hub for Docker, signing keys, authorization,
cookies, CORS, and reverse-proxy configuration.
Documentation
- Installation
- Quick start
- Configuration
- Architecture
- Channels and authorization
- Browser client
- Mercure Hub
- Streaming and deployment
- Testing
- Troubleshooting
Testing
Redis integration tests require a reachable test Redis instance and use a dedicated prefix. See Testing.
License
CodeIgniter SSE is released under the MIT License. CodeIgniter-derived portions retain their notices in Third-party notices.