All Projects → licson → Libsse Php

licson / Libsse Php

Licence: mit
It's an easy-to-use, object-orienlated library for Server-Sent Events

Projects that are alternatives of or similar to Libsse Php

Eventsource
EventSource client for Node.js and Browser (polyfill)
Stars: ✭ 541 (+260.67%)
Mutual labels:  server-sent-events
Axway Amplify Streams Js
AMPLIFY Streams Javascript package containing SDK, documentation and sample applications
Stars: ✭ 79 (-47.33%)
Mutual labels:  server-sent-events
Fs2 Http
Http Server and client using fs2
Stars: ✭ 132 (-12%)
Mutual labels:  server-sent-events
Golang Sse Todo
golang server sent events (sse) example
Stars: ✭ 23 (-84.67%)
Mutual labels:  server-sent-events
Sse Eventbus
EventBus library for sending events from a Spring appliction to the web browser with SSE
Stars: ✭ 59 (-60.67%)
Mutual labels:  server-sent-events
Demo Spring Sse
'Server-Sent Events (SSE) in Spring 5 with Web MVC and Web Flux' article and source code.
Stars: ✭ 102 (-32%)
Mutual labels:  server-sent-events
Reactive Interaction Gateway
Create low-latency, interactive user experiences for stateless microservices.
Stars: ✭ 465 (+210%)
Mutual labels:  server-sent-events
Gossed
Push the standard output of ANY program to browsers as Server Sent Events
Stars: ✭ 138 (-8%)
Mutual labels:  server-sent-events
Fuse
Multiplayer Online Standard
Stars: ✭ 68 (-54.67%)
Mutual labels:  server-sent-events
Aiohttp Sse
Server-sent events support for aiohttp
Stars: ✭ 125 (-16.67%)
Mutual labels:  server-sent-events
Servicestack.java
ServiceStack Java Libraries and Apps
Stars: ✭ 10 (-93.33%)
Mutual labels:  server-sent-events
Esper
📻 Event Source powered by hyper written in Rust
Stars: ✭ 43 (-71.33%)
Mutual labels:  server-sent-events
Facil.io
Your high performance web application C framework
Stars: ✭ 1,393 (+828.67%)
Mutual labels:  server-sent-events
Sseredis
Redis Streams and PubSub to Server-Sent Event bridge in Go
Stars: ✭ 23 (-84.67%)
Mutual labels:  server-sent-events
Azure Signalr
Azure SignalR Service SDK for .NET
Stars: ✭ 137 (-8.67%)
Mutual labels:  server-sent-events
Swell
Swell: API development tool that enables developers to test endpoints served over streaming technologies including Server-Sent Events (SSE), WebSockets, HTTP2, GraphQL, and gRPC.
Stars: ✭ 517 (+244.67%)
Mutual labels:  server-sent-events
Eventsource
The Hoa\Eventsource library.
Stars: ✭ 99 (-34%)
Mutual labels:  server-sent-events
Algernon
🎩 Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support
Stars: ✭ 1,880 (+1153.33%)
Mutual labels:  server-sent-events
Lib.aspnetcore.serversentevents
Lib.AspNetCore.ServerSentEvents is a library which provides Server-Sent Events (SSE) support for ASP.NET Core
Stars: ✭ 138 (-8%)
Mutual labels:  server-sent-events
Restbed
Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
Stars: ✭ 1,551 (+934%)
Mutual labels:  server-sent-events

libSSE-php

License Build Status

An easy-to-use, object-oriented library for Server-Sent Events

Installation

To install this package you'll need composer.

Run composer require tonyhhyip/sse

Usage

Server-side(PHP):

	<?php
	require_once('/path/to/vendor/autoload.php'); //Load with ClassLoader
	
	use Sse\Event;
	use Sse\SSE;
	
	//create the event handler
	class YourEventHandler implements Event {
		public function update(){
			//Here's the place to send data
			return 'Hello, world!';
		}
		
		public function check(){
			//Here's the place to check when the data needs update
			return true;
		}
	}
	
	$sse = new SSE(); //create a libSSE instance
	$sse->addEventListener('event_name', new YourEventHandler());//register your event handler
	$sse->start();//start the event loop
	?>

Client-side(javascript):

	var sse = new EventSource('path/to/your/sse/script.php');
	sse.addEventListener('event_name',function(e){
		var data = e.data;
		//handle your data here
	},false);

Settings

After you created the libSSE instance, there's some settings for you to control the behaviour. Below is the settings provided by the library.

<?php
	require_once('/path/to/vendor/autoload.php'); //Load with ClassLoader
	
	use Sse\SSE;
	
	$sse = new SSE();
    $sse->set($property, $value);

Direct access of property is kept with magic method for backward compatible.

	<?php
	require_once('/path/to/vendor/autoload.php'); //Load with ClassLoader
	
	use Sse\SSE;
	
	$sse = new SSE();
	
	$sse->exec_limit = 10; //the execution time of the loop in seconds. Default: 600. Set to 0 to allow the script to run as long as possible.
	$sse->sleep_time = 1; //The time to sleep after the data has been sent in seconds. Default: 0.5.
	$sse->client_reconnect = 10; //the time for the client to reconnect after the connection has lost in seconds. Default: 1.
	$sse->use_chunked_encoding = true; //Use chunked encoding. Some server may get problems with this and it defaults to false
	$sse->keep_alive_time = 600; //The interval of sending a signal to keep the connection alive. Default: 300 seconds.
	$sse->allow_cors = true; //Allow cross-domain access? Default: false. If you want others to access this must set to true.
	?>

Updates

  1. Add Support of Symfony Http Foundation Compoent
  2. SSE use magic method instead of direct access
  3. Add Redis and Memcahce Mechnism
  4. Add SessionLike Mechnism
  5. Fixed event loop handling where removing handlers at runtime can result in a broken state.
  6. Use Symfony HttpFoundation StreamedResponse to replace the old version
  7. Add Changelog and contributing guide.

Special For PHP 5.3 and 5.4

If you see and error message like your PHP version does not satisfy that requirement., please remove composer.lock and re-install it.

Documentation

You may find it here. https://github.com/licson0729/libSSE-php/wiki/libSSE-docs

Development

This is an active project. If you want to help me please suggest ideas to me and track issues or find bugs. If you like it, please consider star it to let more people know.

Compatibility

Because server-sent events is a new standard and still in flux, only certain browsers support it. However, polyfill for server-sent events is available. Also on shared hosting, it may disable PHP's set_time_limit function and the library may not work as excepted. There's some settings in the library that can fix it.

Integration with Frameworks

Symfony

    <?php
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sse\SSE;
    
    class DefaultController extends Controller
    {
        /**
         * @Route("/sse", name="sse")
         */
        public function sseAction()
        {
            $sse = new SSE();
            // Add your event listener
            return $sse->createResponse();
        }
    }

Laravel

Please use laravel-sse.

Yii2

Please use yii2-sse.

Contribution

Please see the CONTRIBUTING.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].