#3501 - Poor-mans-Cron
| Identifier | #3501 |
|---|---|
| Issue type | Feature request or suggestion |
| Title | Poor-mans-Cron |
| Status | Completed |
| Tags |
Roadmap: v11 (custom) |
| Handling member | PDStig |
| Version | 11 beta2 |
| Addon | core |
| Description | Allow Cron to work via AJAX requests sent in the background of regular page visits.
Do this automatically if Cron has not been set up properly. Cron should not be flagged as properly running when run via this mode. |
| Steps to reproduce | |
| Additional information | Really I'd prefer to encourage people to just set up Cron properly, but there are pros and cons.
Advantages: - Saves effort of having to set up Cron - Some users may not be able to set up Cron due to lack of knowledge - Some users may not be able to set up Cron due to lack of Cron functionality available to them - Can be used for background caching on a fresh install, to improve perceived initial slowness (to leave a better first impression) Disadvantages: - Irregular Cron - Infrequent Cron (bots probably wouldn't trigger AJAX, and if we did it via something like an <img> tag then onload wouldn't trigger quickly enough) - Likely to cause load spikes |
| Funded? | No |
| Commits | Implemented MANTIS-3501 (Poor-mans-Cron) (25e99811) · Commits · Composr ecosystem / Composr · GitLab |
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".


Comments
You could make a simple bash shell script that calls them in sequence.
I still think this is a good idea, at least initially until you get your site ready to roll and work through the checklist. I must install Composr at least twice a week to try something different or because I've ended up with an error I have no idea how to fix (catalogues mainly, got a couple of bugs to report once I work out how I managed to create them). So I wouldn't want to set up cronjobs in those instances, for it to work (in any fashion) would be useful although I agree it's not the best solution it is a handy thing.
----
1 big problem with Poor Man's CRON I realised is when creating clone test sites. If CRON is going to automatically work, then all kinds of background tasks like birthday emails are going to run from the clone site, spamming real users.
Of course, that could happen for other things like if users have notifications on, but that'd be a much smaller problem.
Ideally someone making a clone site would disable e-mails on it via the mail_queue_debug option, but it takes time to get to the admin config to do that and by then loads of emails could have gone out.
EDIT: I've edited the clone site tutorial to mention disabling email in _config.php.
The function would only get registered / execute if Cron had not run in the last minute (and if a config option for web request based triggers is enabled).
Currently, cron_bridge itself has its own "max execution time" and query limit, so it will terminate itself without PHP's help after 8 seconds or 3,900 database queries. This would have been the crucial reason not to use register_shutdown_function in the past because it does not respect PHP's max_execution_time.
The only downside is servers which do not support register_shutdown_function. We could instead then have it execute alongside their request (but this would slow down page load) with a much more conservative 3-second execution limit.
AJAX would nix that problem but introduce other problems such as CSP, whether JavaScript is enabled, and what if a user navigates away before it's finished?
We could use a webhook method... if register_shutdown_function is not available, then use cURL to call the cron bridge asynchronously.
I'll try some of these methods.
Implement ability to use web requests as a way to run scheduled tasks.
The approach I went is different from the original issue:
- Instead of AJAX requests, this uses register shutdown function (if available) when calling a webpage (running_script('index')). And it will only call scheduled tasks via web requests if explicitly enabled in a new configuration option. The reason for this approach is to keep the burden and responsibility off of the client's JavaScript. AJAX could affect rate limiting / banning of the client when it should not (e.g. the AJAX call could result in an additional count against the client for page requests, whether in Composr or on the server end, which is unfair to the client as this is the server's responsibility to handle; it also makes it harder to determine in access logs when someone is trying to abuse cron_bridge.php).
- This *will* (opposed to the issue's desire to not) mark Cron as functioning properly. This is because the admin has to explicitly enable this feature opposed to it happening automatically by default, and the admin should know when for whatever reason this feature is not working.
Notes:
Advantage "Can be used for background caching on a fresh install, to improve perceived initial slowness (to leave a better first impression)" does NOT apply for this approach since the feature has to be explicitly enabled in configuration.
Disadvantage "bots probably wouldn't trigger AJAX, and if we did it via something like an <img> tag then onload wouldn't trigger quickly enough" does NOT apply. If a bot hits an actual webpage, that will also trigger scheduled tasks to run.