30 lines
559 B
PHP
30 lines
559 B
PHP
|
<?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);
|
||
|
}
|