Giter Site home page Giter Site logo

sse's Introduction

Screenshot

Server-Sent Events in PHP

Coverage Maintainability CGL Tests Supported PHP Versions

A server implementation of 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

  • Server implementation of server-sent events (SSE)
  • Highly customizable via interface implementations
  • Self-emitting event stream
  • PSR-7 compliant event stream

๐Ÿ”ฅ Installation

Packagist Packagist Downloads

composer require eliashaeussler/sse

โšก 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

Event stream

All events are sent through event streams. The library provides an interface Stream\EventStream that abstracts all stream parts during the whole event streaming progress.

The following event stream implementations are currently available:

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

Emitter

All data of a self-emitting event stream is handed over to a given emitter. The library provides an interface Stream\Emitter\Emitter that takes care of all passed data.

The following emitter implementations are currently available:

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 interface. Each event must provide an event name and JSON-serializable event data.

๐Ÿง‘โ€๐Ÿ’ป Contributing

Please have a look at CONTRIBUTING.md.

โญ License

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

sse's People

Contributors

eliashaeussler avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

sse's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • php ~8.1.0 || ~8.2.0 || ~8.3.0
  • php-http/discovery ^1.18
  • psr/http-factory ^1.0
  • psr/http-message ^1.0 || ^2.0
  • armin/editorconfig-cli ^1.6
  • eliashaeussler/php-cs-fixer-config ^1.2
  • eliashaeussler/phpstan-config ^2.1
  • eliashaeussler/rector-config ^2.0
  • ergebnis/composer-normalize ^2.31
  • nyholm/psr7 ^1.8
  • phpstan/extension-installer ^1.3
  • phpstan/phpstan-phpunit ^1.3
  • phpstan/phpstan-symfony ^1.3
  • phpunit/phpunit ^10.2
github-actions
.github/workflows/cgl.yaml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • ramsey/composer-install v2
.github/workflows/release.yaml
  • actions/checkout v4
  • ncipollo/release-action v1
.github/workflows/tests.yaml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • ramsey/composer-install v2
  • actions/checkout v4
  • shivammathur/setup-php v2
  • ramsey/composer-install v2
  • paambaati/codeclimate-action v5.0.0
  • codecov/codecov-action v3
regex
.github/workflows/cgl.yaml
  • php 8.3
.github/workflows/tests.yaml
  • php 8.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.