Download the PHP package clue/reactphp-eventsource without Composer

On this page you can find all versions of the php package clue/reactphp-eventsource. 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 reactphp-eventsource

clue/reactphp-eventsource

CI status installs on Packagist

Instant real-time updates. Lightweight EventSource client receiving live messages via HTML5 Server-Sent Events (SSE). Fast stream processing built on top of ReactPHP's event-driven architecture.

Table of contents

Support us

We invest a lot of time developing, maintaining and updating our awesome open-source projects. You can help us sustain this high-quality of our work by becoming a sponsor on GitHub. Sponsors get numerous benefits in return, see our sponsoring page for details.

Let's take these projects to the next level together! 🚀

Quickstart example

Once installed, you can use the following code to stream messages from any Server-Sent Events (SSE) server endpoint:

See the examples.

Usage

EventSource

The EventSource class is responsible for communication with the remote Server-Sent Events (SSE) endpoint.

The EventSource object works very similar to the one found in common web browsers. Unless otherwise noted, it follows the same semantics as defined under https://html.spec.whatwg.org/multipage/server-sent-events.html

Its constructor simply requires the URL to the remote Server-Sent Events (SSE) endpoint:

If you need custom connector settings (DNS resolution, TLS parameters, timeouts, proxy servers etc.), you can explicitly pass a custom instance of the ConnectorInterface to the Browser instance and pass it as an additional argument to the EventSource like this:

This class takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use for this object. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

message event

The message event will be emitted whenever an EventSource message is received.

The EventSource stream may emit any number of messages over its lifetime. Each message event will receive a MessageEvent object.

The MessageEvent::$data property can be used to access the message payload data. It is commonly used for transporting structured data such as JSON:

The EventSource stream may specify an event type for each incoming message. This event field can be used to emit appropriate event types like this:

See also MessageEvent::$type property for more details.

open event

The open event will be emitted when the EventSource connection is successfully established.

Once the EventSource connection is open, it may emit any number of message events.

If the connection can not be opened successfully, it will emit an error event instead.

error event

The error event will be emitted when the EventSource connection fails. The event receives a single Exception argument for the error instance.

The EventSource connection will be retried automatically when it is temporarily disconnected. If the server sends a non-successful HTTP status code or an invalid Content-Type response header, the connection will fail permanently.

See also the EventSource::$readyState property.

EventSource::$readyState

The int $readyState property can be used to check the current EventSource connection state.

The state is read-only and can be in one of three states over its lifetime:

EventSource::$url

The readonly string $url property can be used to get the EventSource URL as given to the constructor.

close()

The close(): void method can be used to forcefully close the EventSource connection.

This will close any active connections or connection attempts and go into the EventSource::CLOSED state.

MessageEvent

The MessageEvent class represents an incoming EventSource message.

MessageEvent::__construct()

The new MessageEvent(string $data, string $lastEventId = '', string $type = 'message') constructor can be used to create a new MessageEvent instance.

This is mostly used internally to represent each incoming message event (see also message event). Likewise, you can also use this class in test cases to test how your application reacts to incoming messages.

The constructor validates and initializes all properties of this class. It throws an InvalidArgumentException if any parameters are invalid.

MessageEvent::$data

The readonly string $data property can be used to access the message payload data.

The data field may also span multiple lines. This is commonly used for transporting structured data such as JSON:

If the message does not contain a data field or the data field is empty, the message will be discarded without emitting an event.

MessageEvent::$lastEventId

The readonly string $lastEventId property can be used to access the last event ID.

Internally, the id field will automatically be used as the Last-Event-ID HTTP request header in case the connection is interrupted.

If the message does not contain an id field, the $lastEventId property will be the value of the last ID received. If no previous message contained an ID, it will default to an empty string.

MessageEvent::$type

The readonly string $type property can be used to access the message event type.

Internally, the event field will be used to emit the appropriate event type. See also message event.

If the message does not contain a event field or the event field is empty, the $type property will default to message.

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

See also the CHANGELOG for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.4 through current PHP 8+. It's highly recommended to use the latest supported PHP version for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

To run the test suite, go to the project root and run:

The test suite is set up to always ensure 100% code coverage across all supported environments. If you have the Xdebug extension installed, you can also generate a code coverage report locally like this:

License

This project is released under the permissive MIT license.

Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

More


All versions of reactphp-eventsource with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
evenement/evenement Version ^3.0 || ^2.0
react/event-loop Version ^1.2
react/http Version ^1.6
react/promise Version ^3 || ^2.10 || ^1.2.1
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 clue/reactphp-eventsource contains the following files

Loading the files please wait ....