X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/9c9d2cdf20255611576f6701658551d342f7b4d3..67bff06aa6fd4d7d3a9aefc2919307326fa6d755:/api/common_api.php diff --git a/api/common_api.php b/api/common_api.php index 3681d0a..ccb1442 100644 --- a/api/common_api.php +++ b/api/common_api.php @@ -1,5 +1,5 @@ log()->subscribe($sources); if ($rpc->error) @@ -56,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); } } @@ -65,6 +103,11 @@ 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) { @@ -75,15 +118,32 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu 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); } }