Skip to content

Commit 7d13733

Browse files
authored
Merge pull request #130 from clue-labs/monotonic-timer
Documentation for monotonic time source vs wall-clock time
2 parents 3adbaf9 + 1558f3f commit 7d13733

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

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.
@@ -276,6 +285,17 @@ hello('Tester', $loop);
276285
The execution order of timers scheduled to execute at the same time is
277286
not guaranteed.
278287

288+
This interface suggests that event loop implementations SHOULD use a
289+
monotic time source if available. Given that a monotonic time source is
290+
not available on PHP by default, event loop implementations MAY fall back
291+
to using wall-clock time.
292+
While this does not affect many common use cases, this is an important
293+
distinction for programs that rely on a high time precision or on systems
294+
that are subject to discontinuous time adjustments (time jumps).
295+
This means that if you schedule a timer to trigger in 30s and then adjust
296+
your system time forward by 20s, the timer SHOULD still trigger in 30s.
297+
See also [event loop implementations](#loop-implementations) for more details.
298+
279299
#### addPeriodicTimer()
280300

281301
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
@@ -232,6 +232,17 @@ public function addTimer($interval, callable $callback);
232232
* The execution order of timers scheduled to execute at the same time is
233233
* not guaranteed.
234234
*
235+
* This interface suggests that event loop implementations SHOULD use a
236+
* monotic time source if available. Given that a monotonic time source is
237+
* not available on PHP by default, event loop implementations MAY fall back
238+
* to using wall-clock time.
239+
* While this does not affect many common use cases, this is an important
240+
* distinction for programs that rely on a high time precision or on systems
241+
* that are subject to discontinuous time adjustments (time jumps).
242+
* This means that if you schedule a timer to trigger in 30s and then adjust
243+
* your system time forward by 20s, the timer SHOULD still trigger in 30s.
244+
* See also [event loop implementations](#loop-implementations) for more details.
245+
*
235246
* @param int|float $interval The number of seconds to wait before execution.
236247
* @param callable $callback The callback to invoke.
237248
*

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)