Using timers (crons)

After upgrading from 1.6 to 2020, I noticed a new feature called Timers (Crons). As I understood it, the feature would allow:

  1. setting an arbitrary number of timers
  2. each timer firing at arbitrary times (with millisecond precision)
  3. when a timer fires, it would execute a specific PHP code, in background

What I discovered, in practice, was that:

  1. While code in a timer is running, no other timer is firing – so setting up multiple timers is useless, as well as expecting them to fire at a fixed interval, as long as another or a previous timer code is still executing.
  2. At least when the timer starts, for a few seconds, if not throughout its whole execution, the main application window becomes non-responsive, it loses window decorations, the mouse cursor turns to spinning circle etc. – so if you set a timer code to run every few seconds the application becomes essentially unusable.
  3. While the timer code is running, it seems that no other pages would be served to the main application (i.e. navigation or ajax calls are paused or seriously slowed down while running code in a timer).

Has anyone else experienced this? Is it something that I’m doing wrong? How are the timers supposed to work? It would seem that only chunks of code that run very seldom and complete very fast would be suitable for running inside a timer, or else the app would look impaired.

It depends on what your PHP code in the timer performs. In some cases, it is better to use AJAX calls because they do not interfere with the UI for instance.

Yea, using AJAX is much more responsive. No more UI freezes, no more Window not responding. Too bad timers can’t be used in a truly parallel/background way though.

Yes, it’s a known limitation but it’s how they are designed.