XF 2.0 Moving cron jobs to an actual crontab

mejicat

Member
Hello,
I'm quite new to XF2, and I'm still sort-of figuring out how things work.

It seems that "cron jobs" in XF2 aren't actually inserted into a crontab, but are handled by the software according to their schedule. Since PHP is stateless and would need some special configuration to actually have a "job process" running, I guess that actual jobs are run either on page loads or somehow via AJAX. This poses a few problems:
  1. if nobody visits a page during a time interval when cron jobs are scheduled, jobs are postponed and run (at the same time? in different requests?) at the first request.
  2. if jobs are run on page loads, responses are slowed down since the job must run before displaying the page. while XF2 is generally very fast, I've experienced a few times where pages took up to 5 seconds to load, and I suspect cron jobs are responsible.
  3. if they're run continuously via AJAX, it's just a waste of people's bandwidth and totally unnecessary.
The best solution, I think, would be to allow running cron jobs server side via an actual crontab. A CLI script (php cmd.php xf:cron?) that is called every minute and executes all queued jobs sequentially, and that can run indefinitely without timeouts. I understand that many of your users are on shared hosting (hopefully less and less each day) and do not have access to crontabs, but this would be very nice for bigger boards who have a lot of jobs running. (Also, IPB had it for years!)

Of course this is assuming something like that doesn't exist already... I tried looking through the official docs and the forums, but I couldn't find anything for XF2!
 
Last edited:
Just came across your old post, just thought I'd mention this FYI: https://xenforo.com/community/resources/cli-job-runner.6478/

FWIW, I think the built in cron/job system in XF2 is pretty robust and in general it should not cause slow page loads. In my experience, that's more likely a transient network issue, or the database is locked while waiting for some other process to finish.

But I think running the jobs independently of visitor activity has merit and using unix cron gives us a lot more flexibility - hence why I built that tool.
 
  • Like
Reactions: rdn
Thanks for telling me! Yes, the cron system in XF2 is not bad at all, but I think it's just stupid in principle to couple cron jobs with requests to the server when you have access to an actual crontab. I will definitely try your extension on my board, and thanks again for stopping by this topic, otherwise I never would've known about it!
 
Top Bottom