<?php
// Run manually or via Windows Task Scheduler every 10 seconds/minute as needed.
// Example: php C:\Apache24\htdocs\mikrotik\admin\cron\update_ppp_cache.php
@set_time_limit(20);
if (PHP_SAPI !== 'cli') { header('Content-Type: application/json; charset=utf-8'); }
require_once __DIR__ . '/../db_bootstrap.php';
require_once __DIR__ . '/../mikrotik_lib.php';
require_once __DIR__ . '/../ppp_active_cache_lib.php';
if (function_exists('ensure_db')) ensure_db(true);
$conn = $GLOBALS['conn'] ?? null;
if (!($conn instanceof mysqli)) { echo json_encode(['ok'=>false,'message'=>'DB connection failed'], JSON_UNESCAPED_UNICODE); exit(1); }
$data = ua_ppp_cache_rebuild($conn, 10, true);
echo json_encode(['ok'=>!empty($data['ok']),'online'=>(int)($data['online'] ?? 0),'age'=>(int)($data['age'] ?? 0),'source'=>$data['source'] ?? ''], JSON_UNESCAPED_UNICODE) . PHP_EOL;
