Skip to content

Experimental EventSource / Server-Sent Events implementation for Framework X.

Notifications You must be signed in to change notification settings

devfrey/framework-x-eventsource

Repository files navigation

EventSource / Server-Sent Events for Framework X

This package is an experimental implementation of Server-Sent Events for clue/framework-x. It doesn't require any modifications to the framework.

Feedback is welcome. Hoping to work towards an implementation that can be shipped with Framework X.

Example:

<?php

use Devfrey\FrameworkX\EventSource\BufferedEventStream;
use Devfrey\FrameworkX\EventSource\Event;
use Devfrey\FrameworkX\EventSource\EventSourceHandler;
use React\EventLoop\Loop;

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

$app = new FrameworkX\App();

$app->get('/', new EventSourceHandler($events = new BufferedEventStream()));

// Send a random value every second
Loop::addPeriodicTimer(1.0, function () use ($events) {
    $events->send((new Event())->data(mt_rand()));
});

$app->run();

About

Experimental EventSource / Server-Sent Events implementation for Framework X.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages