You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just for the reference, let me quote from libev's docs:
Unlike EvTimer , EvPeriodic watchers are not based on real time(or relative time, the physical time that passes) but on wall clock time(absolute time, calendar or clock). The difference is that wall clock time can run faster or slower than real time, and time jumps are not uncommon(e.g. when adjusting it).
EvPeriodic watcher can be configured to trigger after some specific point in time. For example, if an EvPeriodic watcher is configured to trigger "in 10 seconds" (e.g. EvLoop::now() + 10.0 , i.e. an absolute time, not a delay), and the system clock is reset to January of the previous year , then it will take a year or more to trigger the event (unlike an EvTimer , which would still trigger roughly 10 seconds after starting it as it uses a relative timeout).
AFAICT React does not currently differentiate between "wall clock time" and "real time", i.e. it likely depends on which loop implementation you're using. I have not confirmed this, but it looks like the loops assume that both would be aligned.
Here's some same code that could help pinpoint this difference:
$loop->addTimer(30.0, function () {
echo'hi';
});
// pseudo code here to advance the system time by 20s:system('date set (date + 20s)');
// when does the timer execute? in 30s or in 10s?$loop->run();
Out of curiosity, do you have any specific use case in mind where this affected you? Can you provide a gist that helps us understand the issues you're having?
Thank you for your research for this issue.
I have wrote a package which likes the system crontab service based on event-loop:php_crontab, and I want that it can works like a real crontab service.
But I found that the event can not be triggered on wall clock time, so I want to find some ways to solve this.
I can't understand the code above. Should I modify the system date to solve this issue?
We may have to check all loop implementations, but for StreamSelectLoop at least, it should trigger all timers on "wall clock timer". This means it will try to trigger all timers on the absolute time stamp calculated when the timer is added. The stream_select() waits for a relative time difference between now and the next timer, so this may in fact ignore any "time jumps" in between. You may be able to circumvent this by adding a dummy timer that forces the loop to reschedule the correct time difference any X seconds like this:
// NO-OP, forces reschulding relative timer offsets every X seconds$loop->addPeriodicTimer(10.0, function () { });
I hope this helps 👍 I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍
Activity
clue commentedon Nov 17, 2016
Just for the reference, let me quote from libev's docs:
http://php.net/manual/en/class.evperiodic.php
AFAICT React does not currently differentiate between "wall clock time" and "real time", i.e. it likely depends on which loop implementation you're using. I have not confirmed this, but it looks like the loops assume that both would be aligned.
Here's some same code that could help pinpoint this difference:
Out of curiosity, do you have any specific use case in mind where this affected you? Can you provide a gist that helps us understand the issues you're having?
white-poto commentedon Nov 18, 2016
Thank you for your research for this issue.
I have wrote a package which likes the system crontab service based on
event-loop:php_crontab, and I want that it can works like a real crontab service.But I found that the event can not be triggered on wall clock time, so I want to find some ways to solve this.
I can't understand the code above. Should I modify the system date to solve this issue?
clue commentedon Nov 18, 2016
Have you tried this an ran into any issues?
We may have to check all loop implementations, but for
StreamSelectLoopat least, it should trigger all timers on "wall clock timer". This means it will try to trigger all timers on the absolute time stamp calculated when the timer is added. Thestream_select()waits for a relative time difference between now and the next timer, so this may in fact ignore any "time jumps" in between. You may be able to circumvent this by adding a dummy timer that forces the loop to reschedule the correct time difference any X seconds like this:I hope this helps 👍 I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍
white-poto commentedon Nov 18, 2016
Thank you for your help and I will try to solve this problem by using a relative timer.