How cron works
Cron is a task scheduler that runs on the server all the time. Its settings hold a list of tasks, each with a run time: every five minutes, every day at three in the morning, on Mondays at eight. When that time comes, cron runs the task and moves on. It works regardless of whether anyone is logged in or visiting the website at that moment.
What cron is used for
- Nightly backups of the database and files.
- Importing stock and prices from suppliers.
- Generating product feeds for price comparison sites and advertising.
- Sending emails – abandoned basket reminders, review requests, newsletters.
- Housekeeping – deleting old logs and temporary files.
WordPress and its “fake” cron
WordPress has its own scheduler, but it only runs when someone opens the website. On a low-traffic site, scheduled tasks therefore run late: a scheduled post isn't published on time or emails don't go out. On a very busy site, it puts needless load on the server with every visit. The fix is to turn off the built-in scheduler and set up a real cron job on the server that triggers it, for example every five minutes.
A real example
An electronics shop pulled stock data from three suppliers. The import ran through WordPress's built-in scheduler, so it started at random times during the day whenever someone visited the site. Pages could then take tens of seconds to load for customers. After moving the import to a server cron job at two in the morning, the slowdowns disappeared and stock is always up to date in the morning. Scheduled tasks such as stock imports are a standard part of custom web applications.
Tips
- Schedule heavy tasks at night, when traffic is lowest.
- Set up an alert for when a task fails. Otherwise you may only find out your backups weren't working when you need them.
- With cheap hosting, check whether cron is supported at all and how often it can run.