Download the PHP package sinemacula/laravel-sse without Composer

On this page you can find all versions of the php package sinemacula/laravel-sse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-sse

Laravel SSE

[![Latest Stable Version](https://img.shields.io/packagist/v/sinemacula/laravel-sse.svg)](https://packagist.org/packages/sinemacula/laravel-sse) [![PHP Version](https://img.shields.io/packagist/dependency-v/sinemacula/laravel-sse/php.svg)](https://packagist.org/packages/sinemacula/laravel-sse) [![Laravel Version](https://img.shields.io/packagist/dependency-v/sinemacula/laravel-sse/laravel/framework.svg?label=laravel)](https://packagist.org/packages/sinemacula/laravel-sse) [![Build Status](https://github.com/sinemacula/laravel-sse/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-sse/actions/workflows/tests.yml) [![Quality Gates](https://github.com/sinemacula/laravel-sse/actions/workflows/quality-gates.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-sse/actions/workflows/quality-gates.yml) [![Maintainability](https://qlty.sh/gh/sinemacula/projects/laravel-sse/maintainability.svg)](https://qlty.sh/gh/sinemacula/projects/laravel-sse) [![Code Coverage](https://qlty.sh/gh/sinemacula/projects/laravel-sse/coverage.svg)](https://qlty.sh/gh/sinemacula/projects/laravel-sse) [![Total Downloads](https://img.shields.io/packagist/dt/sinemacula/laravel-sse.svg)](https://packagist.org/packages/sinemacula/laravel-sse) [![License](https://img.shields.io/github/license/sinemacula/laravel-sse.svg)](LICENSE)

Server-Sent Events (SSE) streaming primitives for Laravel - an event stream response built around a heartbeat polling loop and a typed emitter. Drop the EventStream into any class, or mix the RespondsWithEventStream trait into a controller, and stream text/event-stream responses without hand-assembling the SSE wire format.

The package ships no service provider, no config file, and no artisan commands - it is a small set of primitives you compose into your own endpoints.

How It Works

An EventStream owns the transport lifecycle: it builds a StreamedResponse with the required SSE headers, runs a polling loop, emits keep-alive heartbeats, watches for client disconnects, and handles callback errors. On each poll it invokes your callback - optionally handing it an Emitter - then sleeps for the configured interval before polling again.

The Emitter writes the SSE wire format for you: emit() produces data: blocks (JSON-encoding arrays and splitting multi-line strings across separate data: fields), optionally preceded by an event: field, and comment() writes the : keep-alive lines.

A few rules hold across the surface:

Installation

No service provider registration is required. The package ships no artisan commands or config files.

Usage

Standalone - from any class

In a controller - via the trait

The trait exposes heartbeatInterval(), maxStreamDuration(), and maxStreamIterations() as overridable protected methods. (They are methods, not constants: a using class cannot override a trait constant in PHP 8.2+.)

Extending EventStream

Override the protected hooks to customise lifecycle behaviour. onStreamEnd() receives a StreamTerminationReason so you can tell a graceful ceiling-reached close from a client disconnect or an error:

Running SSE under Octane

Under php-fpm each request owns its own process, so a long-lived stream is tolerable - the process dies at request end. Under Laravel Octane (Swoole / RoadRunner) the worker pool is fixed and shared, and the EventStream poll loop holds one worker for the entire lifetime of a connection. A single connection the client never closes pins that worker indefinitely, and enough concurrent connections exhaust the pool and starve unrelated API traffic.

API

EventStream

Method Description
__construct(int $heartbeatInterval = 20, int $maxDuration = 0, int $maxIterations = 0) Construct a stream. maxDuration (seconds) and maxIterations are ceilings after which the stream self-terminates; 0 means unbounded.
toResponse(callable $callback, int $interval = 1, int $status = 200, array $headers = []) Build and return a StreamedResponse with SSE headers and polling loop.
onStreamStart(Emitter $emitter) (protected) Called once before the polling loop; emits the initial keep-alive by default.
onStreamEnd(StreamTerminationReason $reason) (protected) Called after the loop exits, with the reason it ended; empty by default.
shouldContinueAfterError(\Throwable, Emitter) (protected) Called on callback exception; returns false to stop, true to continue.

StreamTerminationReason

A string-backed enum passed to onStreamEnd(): CLIENT_DISCONNECT, ERROR, MAX_DURATION, MAX_ITERATIONS.

Emitter

Method Description
emit(array\|string $data, ?string $event = null) Write a data: block (optionally preceded by event:). Arrays are JSON-encoded.
comment(string $text = '') Write a keep-alive comment line.

RespondsWithEventStream trait

Method Description
respondWithEventStream(callable $callback, int $interval = 1, int $status = 200, array $headers = []) Convenience wrapper around EventStream::toResponse().
heartbeatInterval() / maxStreamDuration() / maxStreamIterations() (protected) Override to configure the heartbeat cadence and the stream ceilings. Default to 20 / 0 / 0.

Validation and errors

Requirements

Testing

Changelog

See CHANGELOG.md for a list of notable changes.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.

Security

If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.

License

Licensed under the Apache License, Version 2.0.


All versions of laravel-sse with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^12.9|^13.0
symfony/http-foundation Version ^7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sinemacula/laravel-sse contains the following files

Loading the files please wait ...