PHPackages                             eliashaeussler/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. [HTTP &amp; Networking](/categories/http)
4. /
5. eliashaeussler/sse

ActiveLibrary[HTTP &amp; Networking](/categories/http)

eliashaeussler/sse
==================

PHP implementation of server-sent events using event streams

2.0.0(6mo ago)8340.1k↓19.8%[1 issues](https://github.com/eliashaeussler/sse/issues)2GPL-3.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jun 15Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/eliashaeussler/sse)[ Packagist](https://packagist.org/packages/eliashaeussler/sse)[ RSS](/packages/eliashaeussler-sse/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (13)Versions (7)Used By (2)

[![Screenshot](docs/code-example.png)](#-installation)

Server-Sent Events in PHP
=========================

[](#server-sent-events-in-php)

[![Coverage](https://camo.githubusercontent.com/336ec3a7b42361de5c74c1806db264d6c7dac3717d4de28f90c5ab09a3ffe3ad/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c73436f7665726167652f6769746875622f656c6961736861657573736c65722f7373653f6c6f676f3d636f766572616c6c73)](https://coveralls.io/github/eliashaeussler/sse)[![CGL](https://camo.githubusercontent.com/48bf41488cb063d41a0c592c47d453396f3ba8dae5b3b12173acf9a868c30e99/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6961736861657573736c65722f7373652f63676c2e79616d6c3f6c6162656c3d63676c266c6f676f3d676974687562)](https://github.com/eliashaeussler/sse/actions/workflows/cgl.yaml)[![Tests](https://camo.githubusercontent.com/042f267cbf03f8960556d4d90c0b6a4df4fa0cb80d39e30a673df4fee71ac304/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6961736861657573736c65722f7373652f74657374732e79616d6c3f6c6162656c3d7465737473266c6f676f3d676974687562)](https://github.com/eliashaeussler/sse/actions/workflows/tests.yaml)[![Supported PHP Versions](https://camo.githubusercontent.com/5ed88814172c0c3265ff61127c56766be86894b611c1bf6b23480cd96c53ce30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f656c6961736861657573736c65722f7373652f7068703f6c6f676f3d706870)](https://packagist.org/packages/eliashaeussler/sse)

A server implementation of [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events), written in PHP. It can be used to stream events back to the client. All event-driven features are highly customizable, even custom emitters can be used. The library also provides a PSR-7 compliant event stream implementation.

🚀 Features
----------

[](#-features)

- Server implementation of [server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
- Highly customizable via interface implementations
- Self-emitting event stream
- PSR-7 compliant event stream

🔥 Installation
--------------

[](#-installation)

[![Packagist](https://camo.githubusercontent.com/b939215eb8192a74a7de9cb189a480c4820b24d1015e147004121429528f16b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6961736861657573736c65722f7373653f6c6162656c3d76657273696f6e266c6f676f3d7061636b6167697374)](https://packagist.org/packages/eliashaeussler/sse)[![Packagist Downloads](https://camo.githubusercontent.com/f639ef1e8ddb74720098a943152dfe25fddfb913ad6129467a19465d667b2edc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6961736861657573736c65722f7373653f636f6c6f723d627269676874677265656e)](https://packagist.org/packages/eliashaeussler/sse)

```
composer require eliashaeussler/sse
```

⚡ Usage
-------

[](#-usage)

```
use EliasHaeussler\SSE;

// Open event stream
$eventStream = SSE\Stream\SelfEmittingEventStream::create();
$eventStream->open();

// Send event
$eventStream->sendEvent(new MyCustomEvent($eventData));

// Send message
$eventStream->sendMessage('myCustomEvent', $eventData);

// Close event stream
$eventStream->close();
```

🎢 Architecture
--------------

[](#-architecture)

### Event stream

[](#event-stream)

All events are sent through [event streams](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#sending_events_from_the_server). The library provides an interface [`Stream\EventStream`](src/Stream/EventStream.php) that abstracts all stream parts during the whole event streaming progress.

The following event stream implementations are currently available:

- [**`Stream\SelfEmittingEventStream`**](src/Stream/SelfEmittingEventStream.php)sends all stream data to an [emitter](#emitter) that takes care of writing data into an active resource. This is the best working solution in most cases.
- [**`Stream\Psr7EventStream`**](src/Stream/Psr7EventStream.php) creates a PSR-7 compliant response during the whole event streaming progress. Note that this response is not emitted on real time.

### Emitter

[](#emitter)

All data of a self-emitting event stream is handed over to a given emitter. The library provides an interface [`Stream\Emitter\Emitter`](src/Stream/Emitter/Emitter.php)that takes care of all passed data.

The following emitter implementations are currently available:

- [**`Stream\Emitter\RealtimeEmitter`**](src/Stream/Emitter/RealtimeEmitter.php)writes all stream data directly to the active standard output.

### Event

[](#event)

There are two ways how data can be sent through an active event stream:

1. By sending a prebuilt event by calling `Stream\EventStream::sendEvent()`.
2. By sending a plain message by calling `Stream\EventStream::sendMessage()`.

Events can be generated by implementing the [`Event\Event`](src/Event/Event.php)interface. Each event must provide an event name and JSON-serializable event data.

🧑‍💻 Contributing
----------------

[](#‍-contributing)

Please have a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).

⭐ License
---------

[](#-license)

This project is licensed under [GNU General Public License 3.0 (or later)](LICENSE).

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance79

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 82.6% 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 ~221 days

Total

5

Last Release

181d ago

Major Versions

1.1.1 → 2.0.02025-11-18

PHP version history (4 changes)1.0.0PHP ~8.1.0 || ~8.2.0

1.1.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

1.1.1PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

2.0.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/144cefe55242b883c87cb537463f3ba75a0f8198fc5b602b50c838aae31fe7ee?d=identicon)[eliashaeussler](/maintainers/eliashaeussler)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (418 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (88 commits)")

---

Tags

event-sourceevent-streamsse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eliashaeussler-sse/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[friendsofsymfony/http-cache

Tools to manage HTTP caching proxies with PHP

36114.7M36](/packages/friendsofsymfony-http-cache)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[spiral/roadrunner-http

RoadRunner: HTTP and PSR-7 worker

799.2M48](/packages/spiral-roadrunner-http)[php-soap/psr18-transport

PSR-18 HTTP Client transport for SOAP

183.4M20](/packages/php-soap-psr18-transport)

PHPackages © 2026

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