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

30 lines
559 B
PHP
Raw Normal View History

2022-03-23 09:08:36 +00:00
<?php $app = require '../../app/inc.php';
use App\Timetable\TimeMapper;
use App\SSE\Sender;
$timeMapper = new TimeMapper($app->database->conn);
/**
* Server-Sent Events (SSE)
*/
$sse = new Sender();
$last_change_in_timetable;
while (!connection_aborted())
{
$time = $timeMapper->getLatest();
if ($time)
{
$last_change_in_timetable = $time->date->getTimestamp();
if ($last_time == NULL || $last_change_in_timetable > $last_ajax_call)
{
$sse->send($timeMapper->getAll());
}
}
sleep(1);
}