fbpx

WordPress virtual to real cron job

Spread website joy!

Introduction

This article describes how to configure a virtual to real cron job for WordPress.

Cron is a utility that allows you to set up scheduled tasks on a web server. The WordPress cron system is called WP-Cron, and it simulates the UNIX cron job so you can automate update checks, scheduled posts, and other repetitive tasks.

The virtual WordPress “cron job”

WordPress does not use a real cron job for scheduling and other related tasks by default. Instead, when a page is loaded on a WordPress site, WordPress runs the wp-cron.php file. Although this “virtual” cron job is convenient, it has some disadvantages:

  • Running the wp-cron.php file every time WordPress loads a page is unnecessary, and can negatively affect server performance, particularly on sites that receive a lot of traffic.
  • For a site that does not receive a lot of traffic on the other hand, it can be a significant amount of time before a visitor loads a page (and triggers the cron task). This can cause missed schedules for publishing posts and other unintended effects.
To resolve these issues, you can disable the default virtual WordPress cron job and set up a real cron job. To do this, follow these steps:

Disabling the virtual WordPress cron job

  1. To disable the default virtual WordPress cron job, follow these 4 simple steps:
  2. Log in to your account using cPanel or SSH.
  3. Using the cPanel File Manager or the command line, open the wp-config.php file in a text editor

    The wp-config.php file is located in the directory where you installed WordPress. Usually, this is the public_html directory.

  4. Add the following line to the wp-config.php file right before this line: /* That’s all, stop editing! Happy publishing. */

    define(‘DISABLE_WP_CRON’, true);

  5. Save the changes to the wp-config.php file and then exit the text editor. The virtual WordPress cron job is now disabled.

After you have disabled the default WordPress cron configuration in the wp-config.php file, you are ready to set up a real cron job that runs at fixed intervals regardless of site traffic.

Creating a Real Cron Job Using cPanel

To set up a WordPress cron job using cPanel, follow these steps:

  1. Log in to cPanel.
  2. In the Advanced section of the cPanel home screen, click Cron jobs.
  3. Under Cron Email, type the e-mail address that you want to receive notifications, and then click Update Email. Every time the cron job runs, the e-mail account will receive a message.

    If you do not want to receive e-mail notifications for the cron job, you can append >/dev/null 2>&1 to the command, which redirects all output to /dev/null.

  4. Under Add New Cron Job, in the Common Settings list box, select Twice an hour.

    You can run cron jobs a maximum of every 15 minutes on shared accounts. A 30-minute interval for the WordPress cron job should be more than sufficient.

  5. In the Command text box, type the following line:

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

  6. Click Add New Cron Job. The new cron job settings take effect immediately.

Conclusion

Enabling external cron jobs will reduce resource usage, improve performance, and run jobs more reliably an

Spread website joy!
Inwebify