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

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

lusito/tiny-sse
===============

TinySSE is small helper to publish Server Sent Events aka EventSource.

1.0.0(6y ago)05ZlibPHPPHP ^7.1.0

Since Jun 21Pushed 6y agoCompare

[ Source](https://github.com/Lusito/tiny-sse)[ Packagist](https://packagist.org/packages/lusito/tiny-sse)[ Docs](https://github.com/lusito/tiny-sse)[ RSS](/packages/lusito-tiny-sse/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

TinySSE
=======

[](#tinysse)

[![License](https://camo.githubusercontent.com/b714d5b96797f7b932fd8d67b59d4d2aece0901f8eaed44436dd1d126cb99f87/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d7a6c69622f6c6962706e672d626c75652e737667)](https://github.com/Lusito/tiny-sse/blob/master/LICENSE)

TinySSE is small helper to publish [Server Sent Events](https://en.wikipedia.org/wiki/Server-sent_events) aka EventSource.

### Why TinySSE?

[](#why-tinysse)

- It's minimalistic.
- It packs everything you need:
    - Send all necessary headers.
    - To send events and comments to the client (browser)
    - Detect disconnects.
- TinySSE is released under the liberal zlib/png license.

**Fair warning:** PHP is not a good language for SSE or any other push-style communication, since it will use one thread per request. So you should keep the use at a minimum (like for a limited number of users).

### Example

[](#example)

A simple example:

```
use Lusito\TinySSE;

$lastState = null;
$sse = new TinySSE();

do {
    $state = getState();
    if(statesDiffer($state, $lastState)) {
        $sse->sendEvent(json_encode($state, JSON_UNESCAPED_SLASHES), 'update');
        $lastState = $state;
    }
} while($sse->sleep());
```

### Setup

[](#setup)

Install via composer:

`composer require lusito/tiny-sse`

Include the autoloader in your php script, unless you've done that already:

```
require __DIR__ . '/vendor/autoload.php';
```

### Documentation

[](#documentation)

#### Constructor

[](#constructor)

The constructor takes one optional argument: The number of frames (sleep calls) to count until a comment is flushed to keep the connection alive (int, defaults to 10).

After sleep() has been called this many times without sending anything, a 'noop' comment will be send.

The following headers will be set in the constructor:

- Content-Type: text/event-stream
- Cache-Control: no-cache
- Connection: keep-alive
- X-Accel-Buffering: no

#### sleep()

[](#sleep)

The sleep() method takes two optional parameters:

- The number of seconds to sleep (number, defaults to 1)
- The time limit in seconds.

If you set ignore\_user\_abort to true and the connection has been disconnected, this will return false. Otherwise, it will call set\_time\_limit() with the specified time limit, sleep the specified number of seconds and then return true.

#### sendComment()

[](#sendcomment)

This takes a single string parameter to send as comment. This can contain linebreaks.

The comment will be written to output and flushed.

#### sendEvent()

[](#sendevent)

This takes 3 parameters:

- A string parameter to send as data. This can contain linebreaks.
- An optional event name. No newline is allowed.
- An optional id. No newline is allowed.

This event will be written to output and flushed.

### Report isssues

[](#report-isssues)

Something not working quite as expected? Do you need a feature that has not been implemented yet? Check the [issue tracker](https://github.com/Lusito/tiny-sse/issues) and add a new one if your problem is not already listed. Please try to provide a detailed description of your problem, including the steps to reproduce it.

### Contribute

[](#contribute)

Awesome! If you would like to contribute with a new feature or submit a bugfix, fork this repo and send a pull request. Please, make sure all the unit tests are passing before submitting and add new ones in case you introduced new features.

### License

[](#license)

tiny-sse has been released under the [zlib/libpng](https://github.com/Lusito/tiny-sse/blob/master/LICENSE) license, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects. Credits are appreciated but not mandatory.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

2519d ago

### Community

Maintainers

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

---

Top Contributors

[![Lusito](https://avatars.githubusercontent.com/u/1135267?v=4)](https://github.com/Lusito "Lusito (3 commits)")

---

Tags

pushsseeventsourcepollingServerSentEventscommet

### Embed Badge

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

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

###  Alternatives

[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[symfony/web-link

Manages links between resources

1.4k99.0M251](/packages/symfony-web-link)[symfony/mercure-bundle

Symfony MercureBundle

30813.5M53](/packages/symfony-mercure-bundle)[apple/apn-push

Push notifications to Apple devices

1661.4M3](/packages/apple-apn-push)[eislambey/eventsource

A simple EventSource / SSE (Server-Sent Events) client.

105.9k2](/packages/eislambey-eventsource)[fastgoo/getui-php

个推PHP扩展包

3611.6k](/packages/fastgoo-getui-php)

PHPackages © 2026

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