Make PHP agree with the clock the rest of the server keeps
This commit is contained in:
@@ -56,9 +56,46 @@
|
||||
// varaverk.cfg SCRIPTS_DIR, CUSTOM_SCRIPTS_DIR
|
||||
// master.conf HOST<n> / HOST<n>_NAME — host identity
|
||||
// host*.conf HOST*_SSH_KEY — used for setup-state and conf push
|
||||
// ident.cfg timeZone — Unraid's own setting, adopted for the whole PHP layer
|
||||
// VV_CACHE_DIR /tmp/vv_cache (tmpfs — RAM speed, cleared on reboot)
|
||||
// ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
// ── Timezone ──────────────────────────────────────────────────────────────────
|
||||
// Set here, before anything else, because every PHP entry point in the plugin reaches this file
|
||||
// and nothing that runs earlier has a date in it.
|
||||
//
|
||||
// PHP on Unraid has no date.timezone set and therefore runs in UTC, while the server itself runs
|
||||
// local — America/New_York on this one. Every date this layer produced was consequently offset
|
||||
// from every date the shell layer wrote, and the two are compared constantly: the token ledger,
|
||||
// the rsync history, the arr run dates, the parity cron. The AI tab's "Today" tile read zero for
|
||||
// the four hours between 8pm and midnight, the 7-day windows were cut at the wrong instant, and
|
||||
// the next parity check was displayed four hours out. All of it silent, all of it in the same
|
||||
// direction, all of it invisible for two thirds of the day.
|
||||
//
|
||||
// /etc/php.ini is the wrong place to fix it twice over: /etc is a RAM filesystem here, so the
|
||||
// edit dies at the next reboot, and it would change the timezone for every other PHP application
|
||||
// on the box to fix one of ours.
|
||||
//
|
||||
// ident.cfg is Unraid's own setting, on the flash, and is what the WebGUI's own clock uses — so
|
||||
// this follows the operator's configured timezone rather than asserting one, and a second host
|
||||
// in another zone gets its own. The /etc/localtime symlink is the fallback because it is what
|
||||
// the C library actually honours; UTC last, which is merely today's broken behaviour made
|
||||
// explicit rather than accidental.
|
||||
$_vv_tz = '';
|
||||
foreach (@file('/boot/config/ident.cfg') ?: [] as $_l) {
|
||||
if (preg_match('/^\s*timeZone\s*=\s*"?([^"\r\n]+)"?/', $_l, $_m)) { $_vv_tz = trim($_m[1]); break; }
|
||||
}
|
||||
if ($_vv_tz === '') {
|
||||
$_link = @readlink('/etc/localtime') ?: '';
|
||||
if (preg_match('#zoneinfo/(.+)$#', $_link, $_m)) $_vv_tz = $_m[1];
|
||||
}
|
||||
// Validated before use. An unparseable value would otherwise raise a warning on every request
|
||||
// and leave the process in UTC anyway, which is the bug this exists to remove.
|
||||
if ($_vv_tz === '' || !@timezone_open($_vv_tz)) $_vv_tz = 'UTC';
|
||||
date_default_timezone_set($_vv_tz);
|
||||
define('VV_TIMEZONE', $_vv_tz);
|
||||
unset($_vv_tz, $_l, $_m, $_link);
|
||||
|
||||
define('PLUGIN_CFG', '/boot/config/plugins/varaverk/varaverk.cfg');
|
||||
|
||||
$_vv_cfg = @parse_ini_file(PLUGIN_CFG) ?: [];
|
||||
|
||||
Reference in New Issue
Block a user