faster poll

This commit is contained in:
0xa0
2026-07-22 16:35:17 +02:00
parent 33f3fafb88
commit 6e6052483c
4 changed files with 7 additions and 15 deletions
+4 -13
View File
@@ -2,7 +2,7 @@
require_once __DIR__ . '/config.php';
$cacheFile = DATA_DIR . '/lanyard.json';
$ttl = 15;
$ttl = 2;
if (!function_exists('lanyard_refresh')) {
function lanyard_refresh(string $cacheFile): void {
@@ -21,12 +21,11 @@ if (!function_exists('lanyard_refresh')) {
}
}
$haveCache = is_file($cacheFile);
$stale = !$haveCache || (time() - filemtime($cacheFile) > $ttl);
$isPoll = realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__;
$stale = !is_file($cacheFile) || (time() - filemtime($cacheFile) > $ttl);
if ($stale && !$haveCache) {
if ($stale && ($isPoll || !is_file($cacheFile))) {
lanyard_refresh($cacheFile);
$stale = false;
}
$data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null;
@@ -83,11 +82,3 @@ $banner = $bannerHash
</div>
<?php endif; ?>
</div>
<?php
if ($stale && realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) {
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
lanyard_refresh($cacheFile);
}
?>