CRON and WP Rocket

In this Article

What is Cron?

Cron is a standard utility in Unix and Linux systems, it is used to schedule commands for automatic execution at specific intervals. For instance, you might have a script that produces web stats and you want it to run once a day at a specific hour. Or imagine you need to run a PHP script on weekdays, every 2 hours. 

You can't do these tasks manually and here is where Cron becomes useful. These commands involving Cron are referred to as " cron jobs."

WP-Cron vs "real" Cron jobs

WordPress has a feature called WP-Cron. WP Cron is a built-in function for automation which allows to schedule automated tasks, like publishing posts, maintenance tasks, update checks and by many plugins like WP Rocket which need to automate features.

WP-Cron is not actually a real cron job, you can think it is more like a “fake cron job”. These tasks are triggered when someone visits your site: during PHP page loads, WP Cron checks the database to see if there are any scheduled tasks to execute. 

The way WP Cron works has some drawbacks:

  • When you are using a caching plugin like WP Rocket, no PHP is executed in the frontend, so if there is no activity on WP Admin for some time, WP Cron processes would stop being triggered.
  • It is also a potential issue on high traffic sites, since every page request might spawn a process that uses server resources
  • This file can be used as the target of a DOS attack

Tip: To check if WP-Cron can run on your WordPress site: WP-Cron Status Checker
After activation, visit your Dashboard and look for the WP-Cron Status Checker widget.

Setting up a real Cron Job

Due to WP Cron drawbacks, is always recommended to set up a real Cron job on your server instead of relying on WP Cron.

  1. If you want to create a real Cron job, first you need to disable WP Cron, so is not executed every time someone loads one of your pages. To disable it, open the wp-config.php file in your main WordPress folder and add the following line before the "/* That's all, stop editing! Happy blogging. */" line:

    define('DISABLE_WP_CRON', true);
  2. Add a Cron job entry through your web hosting control panel. You can set the job to run every 5 or 10 minutes.
    Please remember to replace with your actual domain:
    wget -q -O - >/dev/null 2>&1

    Each server has different ways of adding a Cron job, so if you are not sure how to do it you can ask your hosting provider to help you.
    You can check this short video if you are using  cPanel:  

If for any reason, scheduled processes are not properly working, you may notice issues with some of the following WP Rocket features:

  • Cache Preloading
  • Scheduled Cache Clearing
  • Database optimization
  • Critical Path CSS generation for Load CSS Asynchronously
  • Remove Unused CSS
  • Cloudflare add-on

Did you know?
You can extend WP Rocket functionality using Cron to launch custom functions.
For example: How to clear cache via cron job

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.