PHP code example of andersundsehr / server-send-events
1. Go to this page and download the library: Download andersundsehr/server-send-events 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/ */
andersundsehr / server-send-events example snippets
if (ServerSendEventStream::isEventStream($this->request)) {
$stream = new ServerSendEventStream();
$trigger = new FileEventTrigger($stream);
$stopTime = time() + (5 * 60);
do {
$stream->sendMessage($this->getInfo()); // is send to the JS long running script
$trigger->sleepUntilTrigger('changed-' . $currentUser->getUid(), $stopTime);
} while (time() < $stopTime);
die();
}
(new FileEventTrigger())->trigger('changed-' . $currentUser->getUid());