log()->subscribe($sources); if ($rpc->error) { echo $rpc->error; die; } for(;;) { $res = $rpc->eventloop(); if (!$res) { /* Output at least something every timeout (10) seconds, * otherwise PHP may not * notice when the webclient is gone. */ if ($fpm_workaround_needed) echo str_repeat(" ", 4095)."\n"; else echo "\n"; continue; } send_sse($res); } } function api_timer_loop(int $every_msec, string $method, array|null $params = null) { GLOBAL $rpc; /* First, execute it immediately */ $res = $rpc->query($method, $params); if (!$res) die; send_sse($res); $rpc->rpc()->add_timer("timer", $every_msec, $method, $params); if ($rpc->error) { /* Have to resort to old style: client-side timer */ while(1) { $res = $rpc->query($method, $params); if (!$res) die; send_sse($res); usleep($every_msec * 1000); } } /* New style: use server-side timers */ /* - First, execute it immediately */ $res = $rpc->query($method, $params); if (!$res) die; send_sse($res); /* - Then add the timer */ for(;;) { $res = $rpc->eventloop(); if (!$res) { /* Output at least something every timeout (10) seconds, * otherwise PHP may not * notice when the webclient is gone. */ if ($fpm_workaround_needed) echo str_repeat(" ", 4095)."\n"; else echo "\n"; continue; } send_sse($res); } }