1. Go to this page and download the library: Download nerdofcode/laravel-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/ */
nerdofcode / laravel-sse example snippets
use LaravelSSE\Facades\SSE;
Route::get('/stream', function () {
return SSE::create(function () {
return ['time' => now()->toDateTimeString()];
}, 1); // Sends event every 1 second
});
use LaravelSSE\SSE;
Route::get('/stream', function (SSE $sse) {
return $sse->stream(function (SSE $sse) {
$counter = 0;
while ($sse->isConnected() && $counter < 10) {
$sse->json(['count' => ++$counter]);
sleep(1);
}
});
});