<?php
function uptimeGet() {
    $cacheFile = sys_get_temp_dir() . '/h25_uptime.txt';
    $cacheTTL = 300;
    $uptimeText = 'Uptime 99.9%';
    
    if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTTL) {
        $uptimeText = file_get_contents($cacheFile) ?: $uptimeText;
    } else {
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => 'https://stats.uptimerobot.com/KzDXWsqkNr',
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 5
        ]);
        $raw = curl_exec($ch);
        curl_close($ch);
        if (!empty($raw)) {
            $parts = explode('Uptime ', $raw);
            $value = isset($parts[1]) ? explode('Uptime', $parts[1])[0] : '';
            $value = trim(strip_tags($value));
            if (!empty($value) && strlen($value) < 20) {
                $uptimeText = 'Uptime ' . $value;
            }
            file_put_contents($cacheFile, $uptimeText);
        }
    }
    success_response(['uptime' => $uptimeText]);
}