Replace WordPress wp-cron with a real cron

Disabling wp-cron.php in WordPress

WordPress uses a file called wp-cron.php as a virtual cron job, or scheduled task in order to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and more.

By default WordPress is setup to call wp-cron.php every time someone visits your WordPress website when a scheduled task is present, to basically ask "is it time to do anything yet?".

On low traffic sites this is perfectly fine, but when your site visits start to increase, checking multiple times for scheduled tasks can be very inefficient and lead to resource usage problems for the server, this will in turn make your website load slower.

Disable default wp-cron.php behavior

We can easily tell WordPress to let us handle the execution of wp-cron.php with the wp-config.php file.

  1. Open your wp-config.php file with the cPanel File Manager Code Editor
  2. Go to the bottom of the database settings in wp-config.php typically around line 37. Add the code: define('DISABLE_WP_CRON', 'true');
  3. Click Save

Now WordPress will not automatically run the wp-cron.php script each time your site gets a new visitor.

Setup manual cron job for wp-cron.php

For most WordPress users having the wp-cron.php script run every 12 hours is perfectly fine. That would be just 2 executions in a day, compared to possibly hundreds, or even thousands if you had a lot of website traffic that day.

  1. Log into cPanel
  2. Click on cron jobs Under the Advanced section, click on Cron Jobs.
  3. Select Once an hour from the Common Settings drop-down.
  4. Now select Every 12 hours from the Hour drop-down.
  5. Finally fill in the code to run the cron job and click Add New Cron Job - code: /usr/local/bin/php home/username/public_html; php -q wp-cron.php >/dev/null 2>&1 (Where username is your cPanel user name.)

Keep in mind that the /home/username/public_html path would be for a primary domain, if you're using an addon domain, or have WordPress installed in a sub-directory you'll want to be sure to update your path.

You should see that your new cron job was added successfully.

Now WordPress should be safely running scheduled tasks via the wp-cron.php script, but only at set intervals.

  • Disable wp-cron
  • 512 用户发现这很有用
這篇文章有幫助嗎?

相關文章

How to remove multiple posts with a single click in WordPress?

It is possible to remove multiple post in your WordPress dashboard. You can also remove selected...

How to remove your post in Wordpress?

You can remove your published or draft post in Wordpress.1. Login to your WordPress admin...

How to add a new category in WordPress?

1. Login to your WordPress admin dashboard.2. Under the dashboard menu, hover your mouse on Posts...

How to remove the Uncategorized category from WordPress?

You can not remove "Uncategorized" Category but you can rename it1. Login to your WordPress admin...

How to remove a category in WordPress?

If you want to remove WordPress category then follow this instruction:1. Login to your WordPress...