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

34 lines
685 B
PHP
Raw Normal View History

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