There was a problem loading the comments.

Optimizing WordPress Performance with System Cron Jobs (wp-cron.php)

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Introduction to Cron Jobs in WordPress

Cron jobs are a vital component of WordPress, enabling the scheduling of tasks to occur at fixed times, dates, or intervals. These tasks can range from publishing a scheduled post, checking for updates, or triggering a backup plugin on a set schedule.

WordPress employs a built-in cron handler known as WP-Cron to simulate system cron functionality. However, depending on your site's traffic volume, WP-Cron can potentially impact your page load times negatively. This article will guide you on how to disable WP-Cron and instead utilize a system cron for enhanced performance.

 

The Performance Impact of WP-Cron

At Brixly, we manage numerous high-traffic and demanding sites, and we've observed several performance issues associated with WordPress's built-in Cron handler, WP-Cron. It's crucial to understand that WP-Cron is not a genuine cron job; it's a mechanism created by WordPress to emulate what a system cron does.

 

WP-Cron does not operate continuously. By default, wp-cron.php is triggered on every page load, which can cause problems for high-traffic sites. If a site lacks sufficient PHP workers, a request might come in, WordPress will initiate the cron, but the cron has to wait for the worker, resulting in delays.

 

Conversely, if a site has low traffic, schedules could be missed because no one has loaded a page.

 

A more efficient approach is to disable WP-Cron and use the system cron instead. This method operates on a pre-defined schedule and is even recommended in the official Plugin handbook.

 

Disabling WP-Cron

To disable WordPress Cron, insert the following code into your wp-config.php file, just before the line that says "That's all, stop editing! Happy blogging." Please note that this action prevents it from running on page load, not when you call it directly via wp-cron.php.

 

define('DISABLE_WP_CRON', true);

 

Scheduling System Cron

  1. Log in to your cPanel account. In the Advanced section, click on Cron Jobs.
  2. In the 'Add New Cron Job' section, you can select from various pre-defined schedules, such as twice per hour or once per week. Your hosting provider likely has a limit on the frequency of cron jobs. Twice per hour is a common setting for shared hosts.
  3. Enter the following command, replacing https://domain.com with your domain name. This command might vary slightly based on your hosting configuration. Then click on "Add New Cron Job."

 

wget -q -O - https://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

 

Note: The >/dev/null 2>&1 part of the command above suppresses email notifications.


Share via
Did you find this article useful?  

Related Articles

© Brixly