Running Automation via Cron Job
Entry Automation runs scheduled automation actions through WordPress’ task scheduler, via a file named
wp-cron.php runs on every page load, checking to see if there are any scheduled actions waiting to be run. Due to how long Entry Automation tasks can take to run, this can cause performance issues for your users. Additionally, because it only runs on every page load, automation actions might not occur on the scheduled times in your automation configurations.
We can solve this problem by disabling
wp-cron.php and running it automatically via the server’s crontab.
wp-cron.php is as simple as adding one line to your site’s
- Open your
wp-config.phpfile in your text editor of choice.
- Navigate to the area following the database definitions.
- Add the following line:
define( 'DISABLE_WP_CRON', true );
- Save the file and upload it to your site.
Adding a cron job
We now need to add a cron job to the server’s crontab to run
wp-cron.php once every five minutes. You can change the interval to run as often as you’d like. ForGravity recommends not setting the interval to above fifteen minutes as automation actions are set to run every quarter-hour.
If you run your own server, adding the cron job is very simple.
- Start the crontab editor: crontab -e
- Add a cron job for
wp-cron.php: */5 * * * * curl http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
This cron job will run the
wp-cron.php every five minutes and not capture the output of the script. You’ll want to replace example.com with the URL of your WordPress site.
Hosting Control Panel
If you have access to a control panel to control your web hosting account, there are guides available for how to add a cron job for the control panel you’re using.
When setting up a cron job via a hosting control panel, you will want to ensure that:
- The cron job is set to run every five minutes.
- The cron job runs the following command:
You’ll want to replace example.com with the URL of your WordPress site.
*/5 * * * * curl http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
Here are guides for how to add a cron job for the most popular hosting control panels: