Download the PHP package machinateur/php-sse without Composer

On this page you can find all versions of the php package machinateur/php-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 php-sse

php-sse

This package implements Server-sent events in PHP, in a framework-agnostic, low-dependency and object-oriented way.

Prerequisites

Yes, you've read that right, PHP 5.6 is the minimum version requirement to be able to use this package. That way, even legacy projects can provide SSE support to client applications.

It might also be a good idea to gobble up all information on SSE from the MDN web docs to get yourself up to speed on the technology. I found it to be an excellent starting point on this topic along with low-level examples.

Installation

Via composer:

Usage

The following is a simple use-case in plain PHP. For a full example (with client code), have a look around the demo directory.

Make sure to read about why to use this package, to make sure it fits your use-case.

To check out the demo, execute php -S 127.0.0.1:8001 -t ./demo in the terminal and open a new tab http://127.0.0.1:8001/message_stream.html. Make sure to check out the network tab of the browser developer tools.

Below are additional explanations of common use-case scenarios.

Recommended headers

Recommended headers can be retrieved from the default implementation of \Machinateur\SSE\MessageStreamInterface.

Logger support

A custom logger can be set using the setter.

A note on logger support: The \Machinateur\SSE\MessageStream class supports a psr logger to inform about shutdown signals (notice) and any output sent to the client (debug). A logger implementation that logs to the message stream itself is available as part of the demo application.

Custom message stream

It's easily possible to create a custom message stream by implementing the \Machinateur\SSE\MessageStreamInterface interface.

When implementing a custom message stream, bear in mind the requirement to support array result and generator function, as imposed by the interface.

Custom messages

It's also possible to create custom messages by simply implementing the \Machinateur\SSE\Message\MessageInterface interface.

Array vs generator

The callback function, which is passed to the \Machinateur\SSE\MessageStreamInterface::run() method, may return an array or be itself a generator function. That freedom of implementation naturally raises the question of werther to use a generator function or not.

It really depends on your use-case, I'd say. For polling situations on the server-side (e.g. consume a message queue) the obvious choice would be the latter, since collecting a bunch of messages and returning them all at once, would make the use of SSE redundant. Why then event support an array return value than? Supporting both could ease the integration and adoption as well as making testing somewhat easier.

It deserves to be mentioned the \Machinateur\SSE\MessageStream (a simple but sufficient implementation of the interface), internally converts any array return value to a generator anyway.

Framework integration

The library does not automatically integrate with frameworks on purpose, to keep it simple. That does not mean it's impossible to use it with a framework.

Using \Symfony\Component\HttpFoundation\Response (symfony) or \Illuminate\Http\Response (laravel) is pretty straightforward.

Usage with other SSE implementations

This library was inspired and influenced by hhxsv5/php-sse, so here is how to achieve interoperability between the two. This example is based on the existing php-fpm example from hhxsv5/php-sse.

About

Here's some basic information on this package itself and the intent behind it.

What is SSE actually?

Traditionally, a web page has to send a request to the server to receive new data; that is, the page requests data from the server. With server-sent events, it's possible for a server to send new data to a web page at any time, by pushing messages to the web page.

(from "Server-sent events" on the MDN web docs)

[...] server-sent events are unidirectional; that is, data messages are delivered in one direction, from the server to the client (such as a user's web browser). That makes them an excellent choice when there's no need to send data from the client to the server in message form. For example, EventSource is a useful approach for handling things like social media status updates, news feeds, or delivering data into a client-side storage [...].

(from "EventSource" on the MDN web docs)

Simply put, SSE allows us to send events to the client web page from the server.

Why use this package?

This package...

When to use this package?

This package can be used to implement simple SSE on the server-side.

The client-side may use an SSE polyfill, like Remy Sharp's EventSource polyfill) or Yaffle's EventSource polyfill, the native browser implementation (see caniuse).

For more complex use-cases, a more flexible alternative like Mercure might be preferable thought.

Useful read

License

It's MIT.


All versions of php-sse with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
psr/log Version ^1.1 || ^2.0 || ^3.0
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 machinateur/php-sse contains the following files

Loading the files please wait ....