]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - api/common_api.php
Move some PHP files from ./ to ./inc: common, connection, header, footer
[irc/unrealircd/unrealircd-webpanel.git] / api / common_api.php
index ad00ecce7040bae95f231492a5d38bd2015e5194..2224b0d5abcc0d6452c2738ba12997b2c167d4b0 100644 (file)
@@ -1,5 +1,7 @@
 <?php
-include "../common.php";
+include "../inc/common.php";
+
+if(session_status() !== PHP_SESSION_ACTIVE) session_start();
 
 if (!isset($_SESSION['id']))
        die("Access denied");
@@ -8,7 +10,7 @@ if (!isset($_SESSION['id']))
 session_write_close();
 
 // Only now make the connection (this can take a short while)
-include "../connection.php";
+include "../inc/connection.php";
 
 // Server Side Events
 header('Content-Type: text/event-stream');
@@ -54,7 +56,14 @@ 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.
+                        */
+                       echo "\n";
                        continue;
+               }
                send_sse($res);
        }
 }
@@ -73,6 +82,7 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu
                        if (!$res)
                                die;
                        send_sse($res);
+                       usleep($every_msec * 1000);
                }
        }
 
@@ -81,7 +91,14 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu
        {
                $res = $rpc->eventloop();
                if (!$res)
+               {
+                       /* Output at least something every timeout (10) seconds,
+                        * otherwise PHP may not
+                        * notice when the webclient is gone.
+                        */
+                       echo "\n";
                        continue;
+               }
                send_sse($res);
        }
 }