]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/common_api.php
2 include "../inc/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 "../inc/connection.php";
16 if (!defined('NO_EVENT_STREAM_HEADER'))
17 header('Content-Type: text/event-stream');
19 // Explicitly disable caching so Varnish and other upstreams won't cache.
20 header("Cache-Control: no-cache, must-revalidate");
22 // Setting this header instructs Nginx to disable fastcgi_buffering and disable
23 // gzip for this request.
24 header('X-Accel-Buffering: no');
29 // Send content immediately
32 // Flush and stop output buffering (eg fastcgi w/NGINX)
36 $ret = @ob_end_flush();
45 /* Send server-sent events (SSE) message */
46 function send_sse($json)
48 echo "data: ".json_encode($json)."\n\n";
51 function api_log_loop($sources)
55 $rpc->log()->subscribe($sources);
64 $res = $rpc->eventloop();
67 /* Output at least something every timeout (10) seconds,
68 * otherwise PHP may not
69 * notice when the webclient is gone.
78 function api_timer_loop(int $every_msec, string $method, array|null $params = null)
82 $rpc->rpc()->add_timer("timer", $every_msec, $method, $params);
85 /* Have to resort to old style: client-side timer */
88 $res = $rpc->query($method, $params);
92 usleep($every_msec * 1000);
96 /* New style: use server-side timers */
99 $res = $rpc->eventloop();
102 /* Output at least something every timeout (10) seconds,
103 * otherwise PHP may not
104 * notice when the webclient is gone.