PHP code example of murdej / sse
1. Go to this page and download the library: Download murdej/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/ */
murdej / sse example snippets
use Murdej\Sse\SseService;
= 0; $i < 4; $i++) {
$sse->sendMessage(['index' => $i, 'dt' => time()]);
sleep(1);
}
javascript
const es = new EventSource('./sse-service.php');
es.onmessage = (messsage) => {
log.innerText += messsage.data + "\n"
}
es.onerror = (ev) => {
es.close();
}