Run the PHP layer on the host's clock, not UTC
PHP defaults to UTC on Unraid while every bash script stamps local time, and the two write into the same files — conf_changes.log was four hours out from every log you would correlate it against. The parsing half was worse: vv_ai_syslog_ts() reads local-time syslog lines through strtotime() under UTC, landing every event four hours early, and the repair sweep bounds its scan to "since the last pass" — so a fault that had just happened could read as four hours old and fall outside the window. Also fixes date-string comparisons against bandwidth and cleanup dbs, which bash writes with local dates.
This commit is contained in:
@@ -111,6 +111,39 @@ define('DEPLOY_DIR', SCRIPTS_DIR . '/Deployment');
|
||||
//
|
||||
// STATE_DIR moved from SCRIPTS_DIR/State_Files to DATA_DIR/state and kept its name, which is why
|
||||
// the 23 call sites in this layer that build on it needed no edits at all.
|
||||
// ── The clock this layer runs on ──────────────────────────────────────────────────────────────
|
||||
// PHP on Unraid defaults to UTC while the host runs local time, and the two halves of Varaverk
|
||||
// write into the same files. Every bash script stamps its log in local time; every PHP writer —
|
||||
// the conf audit trail, the AI worker, the repair sweep, api/system.php — stamped UTC. On this
|
||||
// host that is a four-hour disagreement inside conf_changes.log against every log you would
|
||||
// correlate it with.
|
||||
//
|
||||
// The formatting was the visible half. The damaging half was parsing: vv_ai_syslog_ts() reads
|
||||
// "Aug 14 19:00:01" out of /var/log/syslog, which the system wrote in local time, and handed it
|
||||
// to strtotime() under UTC — landing every syslog event four hours earlier than it happened. The
|
||||
// repair sweep bounds its scan to "since the last pass", so a fault that had just occurred could
|
||||
// read as four hours old and fall outside the window entirely. It would have found nothing and
|
||||
// said so honestly.
|
||||
//
|
||||
// Same correction fixes the date-string comparisons: bandwidth_history.db and arr_cleanup_stats.db
|
||||
// are written by bash with local dates and compared against date('Y-m-d') here, which near
|
||||
// midnight was a day out.
|
||||
//
|
||||
// Set from the host rather than hardcoded, and only when PHP has not been told otherwise, so an
|
||||
// operator who deliberately configures a timezone keeps it.
|
||||
if (!ini_get('date.timezone') || date_default_timezone_get() === 'UTC') {
|
||||
$_vv_tz = @readlink('/etc/localtime') ?: '';
|
||||
$_vv_p = strpos($_vv_tz, 'zoneinfo/');
|
||||
if ($_vv_p !== false) {
|
||||
$_vv_name = substr($_vv_tz, $_vv_p + 9);
|
||||
// Validated against the real list — a malformed link must not leave the clock undefined.
|
||||
if ($_vv_name !== '' && in_array($_vv_name, timezone_identifiers_list(), true)) {
|
||||
date_default_timezone_set($_vv_name);
|
||||
}
|
||||
}
|
||||
unset($_vv_tz, $_vv_p, $_vv_name);
|
||||
}
|
||||
|
||||
define('DATA_DIR', SCRIPTS_DIR . '/data');
|
||||
define('DB_DIR', DATA_DIR . '/db');
|
||||
define('STATE_DIR', DATA_DIR . '/state');
|
||||
|
||||
Reference in New Issue
Block a user