Unix Cron


New member

Since I have control of the server I'm hosting my copy of XenForo, I want to use a real Unix cron instead of having it done with every request.

How do I do this?

Here's my current thinking:

(1) Configure web server to serve a static 1x1 transparent pixel on a request to cron.php (bypasing php, and doesn't require changes to themes or code)

(2) Set up script to invoke php-cli to run cron.php. Call it xenforo-cron.sh

(3) Setup Unix cron to run xenforo-cron.sh every hour.

Is there anything I have to be aware of? I have not yet cracked open the PHP code, but looking around, this should be able to work.


XenForo developer
Staff member
(3) Setup Unix cron to run xenforo-cron.sh every hour..
You'll need to run it much more often than that. There are spread out tasks, and some that may run every 10 minutes.

Cron.php is only hit if it's actually needed. The time of the next run is stored by XF and it's only invoked when that time is in the past.


New member
Ah, it's good to talk to a developer. Thanks for replying to this thread.

I was under the impression that the cron code figures out what tasks needs to run since the last time it got called, so if it runs every hour, it will run anything that was supposed to run since the last time. Would running it every hour instead of every 10 minutes break things?

The main thing I've seen that runs every 10 minutes is the thread count. That doesn't sound critical to me. Are there anything else?

I may still go with your suggestion and run it every 10 minutes, but I need to balance it with the available memory on the system. It's a tiny VM that doesn't do well with heavy swapping.


XenForo developer
Staff member
Well if you call it and there's nothing to do, it will use very little memory. So I'd just call it at least every 10 minutes - but frankly, I probably wouldn't bother overriding the system unless you know it to be a bottleneck.

There won't really be an issue with calling it less often, you will potentially just defer things more often.


New member
We've had malicious folk harass the forum in past incarnations and I don't want to leave an obvious DOS vector open. Maybe I'm irrationally associating this with vB 4.x's cron.php, and XenForo's cron.php actually performs better. Nevertheless, running background processes initiated from external requests is a hack to get around shared hosting restrictions that I don't have.

For (2), I should be able to just invoke cron.php straight from php-cli without having to set any special environmental variables? Ah well, I'll give this a shot and see what happens. Thanks for the info.


Well-known member
Interested in the outcome of this. Did you implement Hosh?
Perhaps there has been an add-on to achieve this within the last 12 mths?