In Unix/Linux, a cron job is a task that can be configured to run at specific times or intervals. This is no different than a Web Job in Azure.
However, in regard to WordPress, crons are invoked from wp-cron.php. For every request, WordPress runs a check to see if it’s time to invoke a cron. This is an unnecessary call and should be avoided. In this article, we will look at the default crons shipped with WordPress and look at ways we can improve our site performance.
Default WordPress Jobs
By default, WordPress ships with several crons:
|Cron Name||Codex Description|
Check WordPress version against the newest version.
The WordPress version, PHP version, and Locale is sent. Checks against the WordPress server at api.wordpress.org server. Will only check if WordPress isn’t installing.
Check plugin versions against the latest versions hosted on WordPress.org.
The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn’t installing.
Check theme versions against the latest versions hosted on WordPress.org.
A list of all themes installed in sent to WP. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn’t installing.
|wp_maybe_auto_update||Performs WordPress automatic background updates.|
|wp_scheduled_delete||Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.|
However, these are not easily visible to the user. Never fear because just like “there’s an app for that”, in WordPress, there’s a Plugin for that! – WP Crontrol (https://wordpress.org/plugins/wp-crontrol/)
This plugin can be used to view crons and modify their recurrence.
An important thing to note is the time/date of when the crons are scheduled to run. If you ever happen to see slowness on your site during this time, you probably want to disable the cron event in question. To disable a cron event, click Edit, then clear the “Next run (UTC)” field (reverts to now) and change the “Event Schedule” to non-repeating like so:
Remember that these events can always run as needed.
Disable All Crons
If you would like to disable all crons, you will need to add this line to your wp-config.php.
Configuring WordPress Crons through Azure Web Jobs
After you’ve disabled the crons by following the step in the previous section. Instead of having WordPress check at each and every request whether a job should run, an alternative solution is to create an Azure Web Job.
Here’s a snippet that can be saved as a .bat file. Be sure to update the x to match your version of PHP.
|"D:\Program Files (x86)\PHP\v5.x\php.exe" D:\home\site\wwwroot\wp-cron.php cli/auto|
Once this .bat file is saved, compress as a .zip and upload your Azure Web Job. Since most of the cron events are scheduled every 12 hours, we recommend the same for this scheduled job.
Now your WordPress website doesn’t have to worry about if/when the cron will get invoked on every single request.