PHPackages                             0ruialvel0/codeigniter4-sse - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. 0ruialvel0/codeigniter4-sse

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

0ruialvel0/codeigniter4-sse
===========================

Simple SSE module for CodeIgniter 4

v1.0.2(7mo ago)314MITPHPPHP &gt;=8.2

Since Oct 3Pushed 6mo agoCompare

[ Source](https://github.com/0RuiAlvel0/codeigniter4-sse)[ Packagist](https://packagist.org/packages/0ruialvel0/codeigniter4-sse)[ RSS](/packages/0ruialvel0-codeigniter4-sse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

CodeIgniter 4 SSE Module
========================

[](#codeigniter-4-sse-module)

Almost(!) plug-and-play Server-Sent Events (SSE) for CI4 apps.

Server-Sent Events (SSE) are a lightweight way for servers to push real-time updates to the browser over a single, long-lived HTTP connection. Unlike WebSockets, SSE is unidirectional—from server to client—and built on standard HTTP, making it easy to implement and scale. A common use case is live notifications: for example, a dashboard can use SSE to instantly alert users when a new order is placed, a remote sensor changes state, or a background job completes—without requiring the client to constantly poll the server.

Installation
------------

[](#installation)

```
composer require 0ruialvel0/codeigniter4-sse
php spark sse:install
```

Tne install command will:

1. Install this file: public/js/sse-client.js. You need this as the event listener on the client side.
2. It will edit your .env file to add some required settings. These settings will be removed when you run the uninstaller. You can manually edit your .env file to add more events (you need to also add the new event listeners in JS).

Configuration
-------------

[](#configuration)

Edit your `.env` file (these lines are created automatically when after you install):

```
SSE_STREAM_DURATION=15
SSE_POLL_INTERVAL=2
SSE_EVENTS=event_name1:event_cache_name1,event_name12:event_cache_name2

```

Usage
-----

[](#usage)

Trigger events from anywhere in your code:

```
cache()->save('event_cache_key1', '1');
```

This will set the corresponding cache file which will trigger the StreamController into sending the event to the JS client.

Practical example
-----------------

[](#practical-example)

1. Assuming a working fresh CI4 install, follow the procedure to install. Then go to app/Controllers/Home.php controller and add

```
cache()->save('event_cache_key1', '1');
```

on the index() method.

2. If everything installed correctly, you should have a public/js/sse-client.js file. open it and change the first trigger to open a browser alert when the event is detected

```
source.addEventListener('event_name1', function(e) {
        const data = JSON.parse(e.data);
        alert('Event 1 triggered at ' + data.timestamp);
        // Add code here, e.g. alert('Event 1 triggered at ');
    });
```

3. For further checks to see if all is good add the following somewhere on the app/Views/welcome\_message.php

```
Class exists?

```

This will be "true" if it all installed well.

4. Observe in wonder: go to  and after a few seconds (actually about the number of seconds you set on SSE\_STREAM\_DURATION, which by default is 15s and set during the script installation) you should see a browser alert with the trigger timestamp. Neat.
5. I forgot the following instruction on the first version of this addin: you must define the following route on your Routes.php file:

```
// SSE route for FL sync notifications
$routes->get('/sse/stream', '\SseModule\Controllers\StreamController::stream');
```

Frontend
--------

[](#frontend)

Include `public/js/`[`sse-client.js`](https://sse-client.js) and customize:

```
source.addEventListener('event_name1', function(e) {
    const data = JSON.parse(e.data);
    // Add code here, e.g. alert('event triggered');
});
```

Uninstall
---------

[](#uninstall)

```
php spark sse:uninstall
composer remove 0ruialvel0/codeigniter4-sse
```

Extend
------

[](#extend)

Add more events in `.env` with this syntax:

```
SSE_EVENTS=event_name1:event_cache_name1,event_name2:event_cache_name2

```

The event\_name part needs to match what you have on your client JS.

Testing
-------

[](#testing)

\*\*\* This is not active yet. I know this may very well be overkill, I am only doing this because I want to learn about unit testing. I am so ignorant that I do not even know if this makes any sense...

This module will include PHPUnit tests for stream output, config parsing, and event logic.

To run tests:

```
composer install
vendor/bin/phpunit
```

Test coverage includes:

- Stream controller output format
- Event triggering logic
- Config parsing
- Spark installer behavior

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance65

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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 ~0 days

Total

3

Last Release

218d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b576cb8ea344cd086525e00e6f1ae368a25a293af48dc31599f8d453ae3f12f2?d=identicon)[0RuiAlvel0](/maintainers/0RuiAlvel0)

---

Top Contributors

[![0RuiAlvel0](https://avatars.githubusercontent.com/u/8639820?v=4)](https://github.com/0RuiAlvel0 "0RuiAlvel0 (11 commits)")

---

Tags

codeignitercodeigniter-librarycodeigniter4phpserversenteventserversentevents

### Embed Badge

![Health badge](/badges/0ruialvel0-codeigniter4-sse/health.svg)

```
[![Health](https://phpackages.com/badges/0ruialvel0-codeigniter4-sse/health.svg)](https://phpackages.com/packages/0ruialvel0-codeigniter4-sse)
```

###  Alternatives

[hermawan/codeigniter4-datatables

Serverside Datatables library for CodeIgniter4

10943.0k3](/packages/hermawan-codeigniter4-datatables)[jason-napolitano/codeigniter4-cart-module

A basic port of the codeigniter 3 cart module for CodeIgniter 4.

5814.8k](/packages/jason-napolitano-codeigniter4-cart-module)

PHPackages © 2026

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