Skip to content

Commit 1558f3f

Browse files
committed
Documentation for monotonic time source vs wall-clock time
1 parent eec2037 commit 1558f3f

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For the code of the current stable 0.4.x release, checkout the
2626
* [ExtLibeventLoop](#extlibeventloop)
2727
* [ExtLibevLoop](#extlibevloop)
2828
* [LoopInterface](#loopinterface)
29-
* [addtimer()](#addtimer)
29+
* [addTimer()](#addtimer)
3030
* [addPeriodicTimer()](#addperiodictimer)
3131
* [cancelTimer()](#canceltimer)
3232
* [isTimerActive()](#istimeractive)
@@ -184,6 +184,15 @@ It is commonly installed as part of many PHP distributions.
184184
If this extension is missing (or you're running on Windows), signal handling is
185185
not supported and throws a `BadMethodCallException` instead.
186186

187+
This event loop is known to rely on wall-clock time to schedule future
188+
timers, because a monotonic time source is not available in PHP by default.
189+
While this does not affect many common use cases, this is an important
190+
distinction for programs that rely on a high time precision or on systems
191+
that are subject to discontinuous time adjustments (time jumps).
192+
This means that if you schedule a timer to trigger in 30s and then adjust
193+
your system time forward by 20s, the timer may trigger in 10s.
194+
See also [`addTimer()`](#addtimer) for more details.
195+
187196
#### ExtEventLoop
188197

189198
An `ext-event` based event loop.
@@ -267,6 +276,17 @@ hello('Tester', $loop);
267276
The execution order of timers scheduled to execute at the same time is
268277
not guaranteed.
269278

279+
This interface suggests that event loop implementations SHOULD use a
280+
monotic time source if available. Given that a monotonic time source is
281+
not available on PHP by default, event loop implementations MAY fall back
282+
to using wall-clock time.
283+
While this does not affect many common use cases, this is an important
284+
distinction for programs that rely on a high time precision or on systems
285+
that are subject to discontinuous time adjustments (time jumps).
286+
This means that if you schedule a timer to trigger in 30s and then adjust
287+
your system time forward by 20s, the timer SHOULD still trigger in 30s.
288+
See also [event loop implementations](#loop-implementations) for more details.
289+
270290
#### addPeriodicTimer()
271291

272292
The `addPeriodicTimer(float $interval, callable $callback): TimerInterface` method can be used to

src/LoopInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ public function addTimer($interval, callable $callback);
224224
* The execution order of timers scheduled to execute at the same time is
225225
* not guaranteed.
226226
*
227+
* This interface suggests that event loop implementations SHOULD use a
228+
* monotic time source if available. Given that a monotonic time source is
229+
* not available on PHP by default, event loop implementations MAY fall back
230+
* to using wall-clock time.
231+
* While this does not affect many common use cases, this is an important
232+
* distinction for programs that rely on a high time precision or on systems
233+
* that are subject to discontinuous time adjustments (time jumps).
234+
* This means that if you schedule a timer to trigger in 30s and then adjust
235+
* your system time forward by 20s, the timer SHOULD still trigger in 30s.
236+
* See also [event loop implementations](#loop-implementations) for more details.
237+
*
227238
* @param int|float $interval The number of seconds to wait before execution.
228239
* @param callable $callback The callback to invoke.
229240
*

src/StreamSelectLoop.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
* If this extension is missing (or you're running on Windows), signal handling is
4040
* not supported and throws a `BadMethodCallException` instead.
4141
*
42+
* This event loop is known to rely on wall-clock time to schedule future
43+
* timers, because a monotonic time source is not available in PHP by default.
44+
* While this does not affect many common use cases, this is an important
45+
* distinction for programs that rely on a high time precision or on systems
46+
* that are subject to discontinuous time adjustments (time jumps).
47+
* This means that if you schedule a timer to trigger in 30s and then adjust
48+
* your system time forward by 20s, the timer may trigger in 10s.
49+
* See also [`addTimer()`](#addtimer) for more details.
50+
*
4251
* @link http://php.net/manual/en/function.stream-select.php
4352
*/
4453
class StreamSelectLoop implements LoopInterface

0 commit comments

Comments
 (0)