PHP code example of lusito / tiny-sse

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

    

lusito / tiny-sse example snippets



use Lusito\TinySSE;

$lastState = null;
$sse = new TinySSE();

do {
    $state = getState();
    if(statesDiffer($state, $lastState)) {
        $sse->sendEvent(json_encode($state, JSON_UNESCAPED_SLASHES), 'update');
        $lastState = $state;
    }
} while($sse->sleep());