format('Y'); $m = (int)$now->format('n'); $d = (int)$now->format('j'); if ($d < $cap_day) { if ($m === 1) { $m = 12; $y -= 1; } else { $m -= 1; } } $anchor = (new DateTime(sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $cap_day), $tz))->getTimestamp(); $period = [ 'period_start' => $anchor, 'rx' => 0, 'tx' => 0, 'last_ing' => 0, 'last_egr' => 0, ]; @file_put_contents($perFile, json_encode($period, JSON_UNESCAPED_SLASHES)); @unlink($lockFile); echo json_encode(['ok' => true]);