Download the PHP package igorw/event-source without Composer

On this page you can find all versions of the php package igorw/event-source. 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 event-source

EventSource

A PHP 5.3 library for creating an EventSource stream.

EventSource or Server-Sent-Events is a W3C specification that defines a protocol and an API for pushing data from the server to the client. This library is a server-side implementation of this protocol.

It is designed to be transport agnostic, allowing you to use it with apache directly or with other webservers, such as mongrel2.

Build Status

Fetch

The recommended way to install EventSource is through composer.

Just create a composer.json file for your project:

And run these two commands to install it:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

Now you can add the autoloader, and you will have access to the library:

Usage

The first thing you need to do is output the EventSource headers, so that the client knows it's talking to an EventSource server.

After that you create a Stream which provides a nice API for creating events. Once you call flush, all queued events are sent to the client.

This example will send a new event every 2 seconds.

And an example JavaScript client:

Advanced

Last event id

When your events have ids, the client will send a Last-Event-ID header on reconnection. You can read this value and re-send any events that occured after the one provided by the user.

Event namespacing

You can namespace events by using the setEvent method on the event. This allows you to bind to those event types specifically on the client side.

Here is a stream that sends two events. One of type foo and one of type bar.

On the client you bind to that event instead of the generic message one. Do note that the message event will not catch these messages.

Sending JSON

In most applications you will want to send more complex data as opposed to simple strings. The recommended way of doing this is to use the JSON format. It can encode and decode nested structures quite well.

On the server side, simply use the json_encode function to encode a value:

On the client side, you can use JSON.parse to decode it. For old browsers, where JSON is not available, see json2.js.

Custom handler

By default the library will assume you are running in a traditional apache-like environment. This means that output happens through echo. If you are using a server that handles web output in a different way (eg. app server), then you will want to change this.

A handler is simply a function that takes a chunk (a single event) and sends it to the client. You can define it as a lambda. Here is the default handler:

You just pass it to the constructor of the stream:

PHP time limit

In some setups it may be required to remove the time limit of the script. If you are having problems with your script dying after 30 or 60 seconds, add this line.

Polyfill

Most old browsers have not implemented EventSource yet. Luckily there is a polyfill available, that allows them to be used in a wider range of browsers.

Tests

$ phpunit

License

MIT, see LICENSE.


All versions of event-source with dependencies

PHP Build Version
Package Version
Requires php Version >=5.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 igorw/event-source contains the following files

Loading the files please wait ....