X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/fd4848e4bc329f633c8faf725f9d4faef27ca54c..67bff06aa6fd4d7d3a9aefc2919307326fa6d755:/api/common_api.php diff --git a/api/common_api.php b/api/common_api.php index 7da12c9..ccb1442 100644 --- a/api/common_api.php +++ b/api/common_api.php @@ -1,5 +1,7 @@ log()->subscribe($sources); if ($rpc->error) @@ -54,7 +84,17 @@ function api_log_loop($sources) { $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); } } @@ -63,18 +103,47 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu { 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) { - echo $rpc->error; - die; + /* 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); } }