1. Go to this page and download the library: Download irap/sse library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
irap / sse example snippets
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
Sse\SSE;
$sse = new SSE();
$sse->set($property, $value);
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.
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();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.