CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

MonotonicClock — monotone Uhr

Zweck

Die Messwerte nehmen nicht ab, selbst wenn die Systemuhr zurückgestellt wird (NTP-Korrektur, manuelle Änderung): Die Differenz stammt aus hrtime().

Wofür und wie zu verwenden

Messung von Intervallen, Rate-Limiting, Timeouts in langlebigen Prozessen (Daemons, Queue-Worker).

Beispiel

$clock = new MonotonicClock('UTC');
$start = $clock->microtime();
// ... the system clock is moved backwards ...
$elapsed = $clock->microtime() - $start;   // still >= 0

Anti-Patterns

Nicht für die „Wanduhr"-Zeit geeignet: Die Messwerte weichen von der realen Uhr ab, nachdem diese verstellt wurde.

Lebenszyklus

stateDiagram-v2
    [*] --> Anchored: new MonotonicClock()
    Anchored --> Reading: now() = anchor + hrtime delta
    Reading --> Reading: monotonic growth
    note right of Reading: system clock jumps\ndo not affect readings

Funktionsvergleich mit Alternativen

Aspekt🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Widerstandsfähigkeit gegen Rückstellung der Systemuhr✅✅❌❌❌❌
Nanosekunden-Basis (hrtime)✅✅❌❌❌❌
Vollständiger Uhr-Vertrag (timestamp/microtime)✅❌❌❌❌❌
Beliebige Ausgabe-Zeitzone✅✅❌❌❌❌
Echtes sleep()/sleepUntil() mit Fortsetzung nach einem Signal✅✅❌❌❌❌
Gesamt🏆 540000

← Zur Funktionsliste


🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano