This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/public/race/stream.php
2022-03-23 14:03:33 +01:00

34 lines
685 B
PHP

<?php $app = require '../../app/inc.php';
use App\Teamtable\TeamMapper;
use App\Timetable\TimeMapper;
use App\SSE\Sender;
$teamMapper = new TimeMapper($app->database->conn);
$timeMapper = new TimeMapper($app->database->conn);
/**
* Server-Sent Events (SSE)
*/
$sse = new Sender();
$sse->start();
$prev_last_insert = NULL;
while (!connection_aborted())
{
$time = $timeMapper->getLatest();
if ($time)
{
$last_insert = $time->date->getTimestamp();
if ($prev_last_insert == NULL || $last_insert > $prev_last_insert)
{
$sse->flush($timeMapper->getAll());
$prev_last_insert = $last_insert;
}
}
sleep(1);
}