The Hoa\Eventsource library.

Overview

Hoa


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\Eventsource

Help on IRC Help on Gitter Documentation Board

This library allows to manipulate the EventSource (aka Server-Sent Events) technology by creating a server.

Learn more.

Installation

With Composer, to include this library into your dependencies, you need to require hoa/eventsource:

$ composer require hoa/eventsource '~3.0'

For more installation procedures, please read the Source page.

Testing

Before running the test suites, the development dependencies must be installed:

$ composer install

Then, to run all the test suites:

$ vendor/bin/hoa test:run

For more information, please read the contributor guide.

Quick usage

We propose as a quick overview to send an unlimited number of events from the server to the client. The client will display all received events. Thus, in Server.php:

$server = new Hoa\Eventsource\Server();

while (true) {
    // “tick” is the event name.
    $server->tick->send(time());
    sleep(1);
}

And in index.html, our client:

<pre id="output"></pre>
<script>
var output = document.getElementById('output');

try {
    var source    = new EventSource('Server.php');
    source.onopen = function () {
        output.appendChild(document.createElement('hr'));

        return;
    };
    source.addEventListener('tick', function (evt) {
        var samp       = document.createElement('samp');
        samp.innerHTML = evt.data + '\n';
        output.appendChild(samp);

        return;
    });
} catch (e) {
    console.log(e);
}
</script>

Start your HTTP server and then open index.html.

The Hoa\Eventsource\Server::setReconnectionTime method allows to redefine the time before the client will reconnect after a disconnection. The Hoa\Eventsource\Server::getLastId method allows to retrieve the last ID sent to the client.

Awecode

The following awecodes show this library in action:

  • Hoa\Eventsource: why and how to use Hoa\Eventsource\Server? A simple and daily useful example will illustrate the EventSource technology (or Server-Send Events).

Documentation

The hack book of Hoa\Eventsource contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.

Comments
  • Disable proxy buffering on nginx

    Disable proxy buffering on nginx

    nginx has, by default, an output buffering. We can turn it off by using the proxy_buffering directive but it can be cumbersome in some cases. We let the user decide whether adding this directive or not. However, we use the X-Accel-Buffering header to disable the buffering for this specific resource. Please, see http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering.

    enhancement 
    opened by Hywan 6
  • Session locking

    Session locking

    Somewhere inside this library some session locking seems to be occuring. Test script:

    <?php
    include __DIR__ . '/../protected/vendor/autoload.php';
    ob_end_flush();
    $server = new \Hoa\Eventsource\Server();
    $i = 0;
    
    while($i < 20) {
        $i++;
        $server->send(time(), $i);
        sleep(1);
    }
    

    This code should send 20 messages over 20 seconds. When calling this from a server in 2 browser tabs, 1 stays empty until all 20 messages have appeared in the other, after which it starts displaying messages. If I instead open 1 tab in private browsing mode both tabs show the messages simultaneously.

    question 
    opened by SamMousa 2
  • Fix namespace case to `Hoa\Eventsource`.

    Fix namespace case to `Hoa\Eventsource`.

    Fix #14.

    The namespace was Hoa\EventSource. This is incorrect because the library name is Eventsource. The namespace is fixed to Hoa\Eventsource, only the first letter is uppercased.

    bug difficulty: casual 
    opened by Hywan 0
  • Client does not accept text/event-stream

    Client does not accept text/event-stream

    Hi,

    I get this error message when trying your sample code:

    Uncaught Hoa\Eventsource\Server::__construct(): (1) Client does not accept text/event-stream. in /app/public/wp-content/plugins/helpie-chat/vendor/hoa/eventsource/Server.php at line 114.

    And the Eventsource works in a simple way when trying without any library like yours.


    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    opened by essekia 0
  • Properly disable output buffering.

    Properly disable output buffering.

    We had some issues with a server which had output_buffering enabled via php.ini. Debugging was made harder due to the fact that the Server creates an output buffer in its constructor, which is a side effect..

    Since output_get_level will reliably tell us if output buffering is enabled, it would be nice to just throw an exception in that case:

        public function __construct($verifyHeaders = true)
        {
            if (true === $verifyHeaders && true === headers_sent($file, $line)) {
                throw new Exception(
                    'Headers already sent in %s at line %d, cannot send data ' .
                    'to client correctly.',
                    0,
                    [$file, $line]
                );
            }
            if(ob_get_level() > 0) { 
                throw new Exception("Output buffering is active");
            }
    

    Alternatively output buffering could be disabled:

      while (@ob_end_flush());
    

    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    bug difficulty: medium in progress 
    opened by SamMousa 4
Releases(3.17.01.10)
  • 3.17.01.10(Jan 10, 2017)

  • 3.16.11.19(Nov 19, 2016)

    • Documentation: New README.md file. (Ivan Enderlin, 2016-10-18T15:35:01+02:00)
    • Documentation: Update support properties. (Ivan Enderlin, 2016-10-05T20:38:20+02:00)
    Source code(tar.gz)
    Source code(zip)
  • 3.16.01.14(Jan 14, 2016)

  • 3.16.01.11(Jan 11, 2016)

    • Quality: Drop PHP5.4. (Ivan Enderlin, 2016-01-11T09:15:26+01:00)
    • Quality: Run devtools:cs. (Ivan Enderlin, 2016-01-09T09:01:22+01:00)
    • Core: Remove Hoa\Core. (Ivan Enderlin, 2016-01-09T08:15:15+01:00)
    • Consistency: Use Hoa\Consistency. (Ivan Enderlin, 2015-12-08T11:10:42+01:00)
    • Exception: Use Hoa\Exception. (Ivan Enderlin, 2015-11-20T07:44:10+01:00)
    Source code(tar.gz)
    Source code(zip)
  • 2.15.08.13(Aug 13, 2015)

    • Add a .gitignore file. (Stéphane HULARD, 2015-08-03T11:28:51+02:00)
    • Fix namespace case to Hoa\Eventsource. (Ivan Enderlin, 2015-07-28T16:04:49+02:00)
    Source code(tar.gz)
    Source code(zip)
  • 2.15.05.29(Jul 28, 2015)

  • 2.15.04.13(Apr 13, 2015)

  • 2.15.02.19(Feb 19, 2015)

    • Add the CHANGELOG.md file. (Ivan Enderlin, 2015-02-19T08:50:50+01:00)
    • Update links in the documentation. (Ivan Enderlin, 2015-01-23T19:25:23+01:00)
    • Happy new year! (Ivan Enderlin, 2015-01-05T14:28:43+01:00)
    Source code(tar.gz)
    Source code(zip)
  • 2.14.12.10(Feb 19, 2015)

  • 2.14.11.26(Feb 19, 2015)

    • Format the composer.json file. (Ivan Enderlin, 2014-11-25T14:17:26+01:00)
    • Require hoa/test. (Alexis von Glasow, 2014-11-25T13:50:12+01:00)
    Source code(tar.gz)
    Source code(zip)
  • 2.14.11.09(Feb 19, 2015)

  • 2.14.09.23(Feb 19, 2015)

  • 2.14.09.17(Feb 19, 2015)

Owner
Hoa
Hoa is a modular, extensible and structured set of PHP libraries.
Hoa
A pragmatic event sourcing library for PHP with a focus on developer experience.

EventSaucePHP EventSauce is a somewhat opinionated, no-nonsense, and easy way to introduce event sourcing into PHP projects. It's designed so storage

EventSauce 685 Dec 31, 2022
The Hoa\Websocket library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Web

Hoa 419 Dec 30, 2022
The Hoa\Eventsource library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Eve

Hoa 106 Dec 5, 2022
[READ-ONLY] The event dispatcher library for CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Event Library This library emulates several aspects of how events are triggered and managed in popular JavaScript libraries such as jQuery: An

CakePHP 21 Oct 6, 2022
🚀 Coroutine-based concurrency library for PHP

English | 中文 Swoole is an event-driven asynchronous & coroutine-based concurrency networking communication engine with high performance written in C++

Swoole Project 17.7k Jan 5, 2023
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

Piotr Śliwa 879 Dec 30, 2022
PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

PEL: PHP Exif Library README file for PEL: PHP Exif Library. A library with support for reading and writing Exif headers in JPEG and TIFF images using

null 264 Dec 4, 2022
BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

null 3 May 18, 2022
EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby

EmailReplyParser EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby.

William Durand 606 Dec 8, 2022
Library JGU is a website created for a university library system information. Made with PHP & TailwindCSS.

Library JGU Library JGU is a website created for a university library system information. Made with PHP & TailwindCSS. Key Features • How To Use • Rel

Azkazikna Ageung Laksana 23 Oct 7, 2022
This library extends the 'League OAuth2 Client' library to provide OpenID Connect Discovery support for supporting providers that expose a .well-known configuration endpoint.

OpenID Connect Discovery support for League - OAuth 2.0 Client This library extends the League OAuth2 Client library to provide OpenID Connect Discove

null 3 Jan 8, 2022
Laravel-Library-Management-system is nice to management library system...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Eng Hasan Hajjar 2 Sep 30, 2022
Simple utility and class library for generating php classes from a wsdl file.

wsdl2phpgenerator Simple WSDL to PHP classes converter. Takes a WSDL file and outputs class files ready to use. Uses the MIT license. Announcement: We

null 802 Dec 10, 2022
A PHP library to support implementing representations for HATEOAS REST web services.

Hateoas A PHP library to support implementing representations for HATEOAS REST web services. Installation Working With Symfony Usage Introduction Conf

William Durand 998 Dec 5, 2022
This PHP library will help you to work with your Pinterest account without using any API account credentials.

Pinterest Bot for PHP A PHP library to help you work with your Pinterest account without API credentials. The Pinterest API is painful: receiving an a

Sergey Zhuk 414 Nov 21, 2022
A simple Monad library for PHP

MonadPHP This is a basic Monad library for PHP. Usage Values are "wrapped" in the monad via either the constructor: new MonadPHP\Identity($value) or t

Anthony Ferrara 283 Dec 29, 2022
A simple library to work with JSON Web Token and JSON Web Signature

JWT A simple library to work with JSON Web Token and JSON Web Signature based on the RFC 7519. Installation Package is available on Packagist, you can

Luís Cobucci 6.8k Jan 3, 2023
Open source social sign on PHP Library. HybridAuth goal is to act as an abstract api between your application and various social apis and identities providers such as Facebook, Twitter and Google.

Hybridauth 3.7.1 Hybridauth enables developers to easily build social applications and tools to engage websites visitors and customers on a social lev

hybridauth 3.3k Dec 23, 2022
PHP 5.3+ oAuth 1/2 Client Library

PHPoAuthLib NOTE: I'm looking for someone who could help to maintain this package alongside me, just because I don't have a ton of time to devote to i

David Desberg 1.1k Dec 27, 2022
PHP library for Two Factor Authentication (TFA / 2FA)

PHP library for Two Factor Authentication PHP library for two-factor (or multi-factor) authentication using TOTP and QR-codes. Inspired by, based on b

Rob Janssen 896 Dec 30, 2022