PHPackages                             webware/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. webware/sse

ActiveLibrary

webware/sse
===========

A PHP library for Server-Sent Events (SSE) that provides a simple and efficient way to send real-time updates from the server to the client.

0.1.x-dev(1mo ago)02↓100%BSD-3-ClausePHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI failing

Since Mar 15Pushed 1mo agoCompare

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

READMEChangelogDependencies (14)Versions (7)Used By (0)

webware/sse
===========

[](#webwaresse)

A Server-Sent Events (SSE) notification component for [Mezzio](https://docs.mezzio.dev/) applications built on the Laminas ecosystem.

- **PSR-7 native** — `SseResponse` extends `Laminas\Diactoros\Response`
- **EmitterStack-aware** — `SseEmitter` implements `EmitterInterface` and returns `false` for non-SSE responses, letting `SapiEmitter` handle the rest
- **PSR-15 request handler** — `NotificationHandler` reads queued messages and streams them as named SSE events
- **Laminas View integration** — each message is rendered through a configurable `.phtml` partial before being sent
- **htmx v2 compatible** — named events map directly to `sse-swap` targets in htmx's `sse` extension
- **Mezzio router integration** — `RouteProvider` registers `/notifications` and its middleware pipeline automatically
- **PSR-11 container** — `ConfigProvider` wires all services; `laminas-servicemanager` is required at runtime

---

Requirements
------------

[](#requirements)

- PHP 8.2–8.5
- `laminas/laminas-diactoros` ^3.0
- `laminas/laminas-httphandlerrunner` ^2.0
- `laminas/laminas-servicemanager` ^4.0
- `laminas/laminas-view`
- `axleus/message` (for `SystemMessengerInterface` and `MessageMiddleware`)
- `mezzio/mezzio` (for `RouteProviderInterface`)

---

Quick Start
-----------

[](#quick-start)

### 1. Install

[](#1-install)

```
composer require webware/sse
```

### 2. Register `ConfigProvider`

[](#2-register-configprovider)

Add `Webware\SSE\ConfigProvider` to your config aggregator. This registers all factories, the `EmitterStack` delegator, the route provider, and the view templates.

```
// config/config.php
use Laminas\ConfigAggregator\ConfigAggregator;
use Webware\SSE\ConfigProvider;

return (new ConfigAggregator([
    ConfigProvider::class,
    // your other providers …
]))->getMergedConfig();
```

### 3. Ensure `SapiEmitter` is on the stack (optional advanced usage)

[](#3-ensure-sapiemitter-is-on-the-stack-optional-advanced-usage)

`ConfigProvider` registers a delegator that pushes `SseEmitter` onto the `EmitterStack`. You must still push `SapiEmitter` below it so that ordinary responses are handled:

```
// register the delegator factory in ConfigProvider
    public function getDependencies(): array
    {
        return [
            'delegators' => [
                EmitterInterface::class => [
                    Container\EmitterStackDelegatorFactory::class,
                ],
            ],
            //....
        ];
    }
```

### 4. Register routes

[](#4-register-routes)

`ConfigProvider` declares `RouteProvider` under `router.route-providers`. If your Mezzio bootstrap processes that key automatically, no extra step is needed.
For manual registration:

```
// config/routes.php
use Webware\SSE\RouteProvider;

(new RouteProvider())->registerRoutes($app, $factory);
```

This registers `GET /notifications` → `SessionMiddleware → MessageMiddleware → NotificationHandler`.

### 5. Wire up the HTML page with htmx

[](#5-wire-up-the-html-page-with-htmx)

Include the htmx `sse` extension and connect to the `/notifications` endpoint. Each incoming SSE event is swapped into the matching `sse-swap` target:

```

```

When `NotificationHandler` processes a request it renders each queued message through its corresponding `sse::` partial and emits the HTML fragment as a named SSE event. htmx routes the event to the matching swap target.

### 6. (Optional) Emit an event manually

[](#6-optional-emit-an-event-manually)

If you need to emit a one-off SSE response from your own handler:

```
use Webware\SSE\Event;
use Webware\SSE\SseResponse;

$event = new Event(
    data:  'Deploy complete.',
    event: 'info',
    id:    'deploy-123',
);

return new SseResponse($event);
```

---

Documentation
-------------

[](#documentation)

DocumentDescription[docs/event.md](docs/event.md)`EventInterface` contract and `Event` value object — constructor, constants, wire-format output[docs/sse-response.md](docs/sse-response.md)`SseResponse` — accepted body types, default headers[docs/sse-emitter.md](docs/sse-emitter.md)`SseEmitter`, `SseEmitterFactory`, `EmitterStackDelegatorFactory`, stack ordering[docs/notification-handler.md](docs/notification-handler.md)`NotificationHandler` request flow, request attributes, `NotificationHandlerFactory`[docs/route-provider.md](docs/route-provider.md)`RouteProvider` middleware pipeline, `RouteProviderFactory`[docs/config-provider.md](docs/config-provider.md)`ConfigProvider` — full config key reference for dependencies, router, and templates[docs/templates.md](docs/templates.md)Template keys, available variables, overriding defaults---

License
-------

[](#license)

BSD-3-Clause. See [LICENSE](LICENSE).

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance95

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d6eed33e61a99f1147789696252f4523130b5035a19eb07e034a7407fd44548?d=identicon)[tyrsson](/maintainers/tyrsson)

---

Top Contributors

[![tyrsson](https://avatars.githubusercontent.com/u/1237487?v=4)](https://github.com/tyrsson "tyrsson (21 commits)")

---

Tags

phpsseserver sent events

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)

PHPackages © 2026

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