]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/common_api.php
2 include "../common.php";
4 if(session_status() !== PHP_SESSION_ACTIVE
) session_start();
6 if (!isset($_SESSION['id']))
9 // Close the session now, otherwise other pages block
10 session_write_close();
12 // Only now make the connection (this can take a short while)
13 include "../connection.php";
16 header('Content-Type: text/event-stream');
18 // Explicitly disable caching so Varnish and other upstreams won't cache.
19 header("Cache-Control: no-cache, must-revalidate");
21 // Setting this header instructs Nginx to disable fastcgi_buffering and disable
22 // gzip for this request.
23 header('X-Accel-Buffering: no');
28 // Send content immediately
34 // If we use fastcgi, then finish the request now (UNTESTED)
35 if (function_exists('fastcgi_finish_request'))
36 fastcgi_finish_request();
38 /* Send server-sent events (SSE) message */
39 function send_sse($json)
41 echo "data: ".json_encode($json)."\n\n";
44 function api_log_loop($sources)
48 $rpc->log()->subscribe($sources);
57 $res = $rpc->eventloop();
60 /* Output at least something every timeout (10) seconds,
61 * otherwise PHP may not
62 * notice when the webclient is gone.
71 function api_timer_loop(int $every_msec, string $method, array|null $params = null)
75 $rpc->rpc()->add_timer("timer", $every_msec, $method, $params);
78 /* Have to resort to old style: client-side timer */
81 $res = $rpc->query($method, $params);
85 usleep($every_msec * 1000);
89 /* New style: use server-side timers */
92 $res = $rpc->eventloop();
95 /* Output at least something every timeout (10) seconds,
96 * otherwise PHP may not
97 * notice when the webclient is gone.