PHP code example of itzyanick / sselib

1. Go to this page and download the library: Download itzyanick/sselib 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/ */

    

itzyanick / sselib example snippets


use ItzYanick\SSELIB\Server;
use ItzYanick\SSELIB\Event;

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('X-Accel-Buffering: no'); // optional

$dataCallback = function ($var, $prevData) {
    $push = ['content' => 'Fools'];
    if (empty($push)) {
        return false;
    }
    return [json_encode(compact('push')), json_encode(compact('push'))];
};

$abortCallback = function () {

};

$server = new Server();
$server->setEvent(new Event($dataCallback, 'data', 'var', $abortCallback));
$server->startServer(0);