Last modified by M. Dara Duman - 6 months ago
673 Views
2 min read

How do I set up WP Cron to make sure it runs on the specified intervals?

WP Cron is a task scheduler used by WordPress and our plugins extensively. WP Cron runs when someone visits your site. In other words, if no one visits your site, WP Cron does not run. In that case, the tasks scheduled by our plugins will not be executed or will be delayed until the next WP Cron run.

To make sure the scheduled tasks are executed in a reliable and predictable way, we have two options:

  • Using operating system task scheduler
  • Using an external webcron service

Before using any of the options above. You need to disable WP Cron from running by adding the following code to your wp-config.php file:

define('DISABLE_WP_CRON', true);

Using operating system task scheduler

You can use your operating system's task scheduler to trigger WP Cron at the specified intervals by following the steps below. Make sure to replace "Your_Site_URL" with your own domain URL.

Windows

There are multiple ways to schedule a task depending on your flavor of Windows. We've found that the easiest way to do it is the command line by using the schtasks command.

  1. Open a command prompt (Start > Programs > Accessories > Command Prompt)
  2. Enter the following code:

    schtasks /create /tn "WordPress Cron Job" /tr "BROWSER_PATH http://Your_Site_URL/wp-cron.php" /sc TIME

Change BROWSER_PATH to the path of the exe file of your favorite browser. For example, "C:\PROGRA~1\MOZILL~1\firefox.exe". Change TIME based on how often you need to run this task. For example, MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY. Check Microsoft schtasks command documentation for more information.

Mac OS X/Linux

  1. Mac OS X and Linux have a time based task scheduler called cron. You can also use launchd service in Mac OSX. To start cron, go to command line and type in the following command: crontab -e
  2. Use the image below to create your cron task:

    Each cron task must be created in a separate line per site. A cron task consists of five parts:

    • minute
    • hour
    • day of month
    • month
    • day of week

    For example, to run WP Cron at minute 5 every hour:

    5 * * * * /usr/bin/wget -q -O - http://example.com/wp-cron.php?doing_wp_cron

    OR

    If wget is not installed, you can use curl. The following command runs every 5 minutes.

    */5 * * * /usr/bin/curl --silent "https://example.com/wp-cron.php?" > /dev/null 2>&1

    Alternatively, you can use special strings to define the time part of your task:

    String

     Alternative

    Definition

    Cron line

    @reboot

     

    Run once, at startup.

     

    @yearly

    @annually

    Run once a year

    0 0 1 1 *

    @monthly

     

    Run once a month

    0 0 1 * *

    @weekly

     

    Run once a week

    0 0 * * 0

    @daily

    @midnight

    Run once a day

    0 0 * * *

    @hourly

     

    Run once an hour

    0 * * * *

    For example, to run WP Cron daily at midnight:

    @daily wget -q -O - http://Your_Site_URL/wp-cron.php?doing_wp_cron

Please note that if you're using our plugins in multiple sites, you should create a task to run WP Cron for every site.

Using an external webcron service

If using operating system level task scheduler is not an option for you. You can use one of the many webcron services to trigger your wp-cron.php at the specified intervals.

Was this information helpful?