AskWael

Menu

WordPress wp-cron Performance Benefits

Language
WordPress wp-cron Performance Benefits

In this article we will discuss how to disable wp-cron.php in order to improve WordPress website performance. WordPress uses wp-cron.php to schedule tasks and run them in the background. As a result of that, WordPress is able to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and more.

WordPress is setup by default to call wp-cron.php every time someone visits your WordPress website. This means with every website visit, wp-cron.php is checking to see if there is a scheduled task present, to basically ask itself to see if there anything it needs to do.

For instance, on low traffic websites 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 eventually make your website load slower.

However, for advanced usage, WordPress has made a way to disable wp-cron.php from running with every website visit. Advanced users should therefore take advantage of that and disable default WordPress settings for wp-cron.php and enable a more advanced option. For example, a typical setting for most WordPress users, is to have 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.

How to disable WordPress wp-cron default behavior

  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

How to setup a real system cron job for WordPress

  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: "php -q /home/username/public_html/wp-cron.php" without quotation marks.

Most importantly, do not forget to replace the path "/home/username/public_html" by the location of your WordPress installation.

Keep in mind that the path "/home/username/public_html" would be for a primary domain. Moreover, If you're using an addon domain, or have WordPress installed in a sub-directory. Be sure to update your path to the correct one.

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

If you are finding this task difficult to complete, reach out to the technical support of your web hosting provider. They should help you with this task. If you are looking for a good web hosting provider, try Greens247 Fast Web Hosting.

More WordPress articles can be found here.