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

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

roiwk/sse-client
================

Server Sent Event client

v1.3.0(2y ago)5791MITPHPPHP &gt;=7.0 | &gt;=8.0

Since Sep 19Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

sse-client
==========

[](#sse-client)

Server Sent Event client
SSE客户端

Install 安装
==========

[](#install-安装)

```
composer require roiwk/sse-client
```

Usage 使用
========

[](#usage-使用)

Client 客户端
----------

[](#client--客户端)

```
include 'path/to/autoload.php';

$client = new Roiwk\SSEClient\Client('http://127.0.0.1:8888');
$client->addEventListener('ping', function ($data) {
    echo "Received ping event: $data\n";
});
$client->start();
```

Server (demo) 服务端
-----------------

[](#server-demo--服务端)

You can use a test server to facilitate the use of this demo client, or use another server. Here is a demo:
你可以使用一个测试服务器,以方便使用此演示客户端,或着使用别的服务端:

[server.php](./example/server.php)

```
php -S 127.0.0.1 server.php
```

Advanced 高级用法
=============

[](#advanced-高级用法)

Parameters and methods 参数与方法
----------------------------

[](#parameters-and-methods-参数与方法)

更多http context选项, 详见[php.net](https://www.php.net/manual/zh/context.http.php)

```
// construct usage
$client = new Roiwk\SSEClient\Client('http://127.0.0.1:8888', [
    'retryInterval' => 3,
    'onmessage' => function(string $data){},
    'streamContextOptions' => [
        'http' => [
            'method' => 'POST',
            'header' => [
                'Content-Type: application/json',
            ],
            'content' => json_encode(['test' => 1]),
        ],
    ],
]);

// method usage
$client->addEventListener('ping', function ($data) {
    echo "Received ping event: $data\n";
});

$client->onmessage(function(string $data) use ($client){
    echo $data.PHP_EOL;
    $iWantClose = true;
    if ($iWantClose) {
        $client->close();
    }
});

$client->setRetryInterval(1);

$client->start();
```

Tips
----

[](#tips)

> 1. If the server sends messages without an event field, those messages are treated as message events.
> 2. 如果服务器发送的消息中没有 event 字段，则这些消息会被视为 message 事件。

> 2. The close method can be executed in the callback, for example: addEventListener and onmessage, onerror.
> 3. close方法可以在回调中执行, 例如:addEventListener和onmessage,onerror.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

2

Last Release

970d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1beffb7f6ed8456ac0dff0c7f864036e80f1404332ff118d1ebd0e0026d284e0?d=identicon)[roiwk](/maintainers/roiwk)

---

Top Contributors

[![roiwk](https://avatars.githubusercontent.com/u/21002823?v=4)](https://github.com/roiwk "roiwk (2 commits)")[![codinglist](https://avatars.githubusercontent.com/u/49902313?v=4)](https://github.com/codinglist "codinglist (1 commits)")

---

Tags

sseserver sent eventsSSE client

### Embed Badge

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

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

###  Alternatives

[symfony/mercure

Symfony Mercure Component

43915.1M28](/packages/symfony-mercure)[qruto/laravel-wave

Painless Laravel Broadcasting with SSE.

87048.4k](/packages/qruto-laravel-wave)[hhxsv5/php-sse

A simple and efficient library implemented HTML5's server-sent events by PHP, is used to real-time push events from server to client, and easier than Websocket, instead of AJAX request.

452178.0k3](/packages/hhxsv5-php-sse)[mvanduijker/laravel-mercure-broadcaster

Mercure broadcaster

16866.5k](/packages/mvanduijker-laravel-mercure-broadcaster)[igorw/event-source

A PHP 5.3 library for creating an EventSource stream.

10488.7k2](/packages/igorw-event-source)[tonyhhyip/sse

An easy-to-use, object-oriented library for Server-Sent Events

24165.9k2](/packages/tonyhhyip-sse)

PHPackages © 2026

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