Skip to content

marko-php/marko-sse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

marko/sse

Server-Sent Events for Marko — push real-time updates to browsers without WebSockets.

Installation

composer require marko/sse

Quick Example

use Marko\Sse\SseEvent;
use Marko\Sse\SseStream;
use Marko\Sse\StreamingResponse;

$stream = new SseStream(
    dataProvider: function () use (&$lastEventId): array {
        $messages = $this->messages->findSince($lastEventId);

        return array_map(fn ($msg) => new SseEvent(
            data: ['id' => $msg->id, 'text' => $msg->body],
            event: 'message',
            id: $msg->id,
        ), $messages);
    },
    pollInterval: 1,
    timeout: 300,
);

return new StreamingResponse($stream);

Documentation

Full usage, API reference, and examples: marko/sse

About

[READ-ONLY] Server-Sent Events (SSE) support for Marko Framework. Issues and PRs at https://github.com/marko-php/marko

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages