Run WordPress wp-cron.php With a Server-Side Cron Job for Better Performance

WordPress uses the wp-cron.php file to automate certain tasks. This way, WordPress can, for example, look for theme and plugin updates in the background and publish scheduled posts automatically.

wp-cron.php is called every time someone visits your website. This can be inefficient for sites with a lot of traffic and can make your website load slower. To increase performance of your website, you can disable the default wp-cron.php behaviour and set up a real, server side cron job for your website.

Requires a contract with SSH support.

Disable wp-cron.php excecution through WordPress

Connect to your webspace using SFTP and open the root folder of your WordPress website. Learn more (1&1 Help Center)

Open the wp-config.php file with a text editor like Notepad++.

Add the following line (bold) to your wp-config.php, right below <?php:

<?php

define('DISABLE_WP_CRON', 'true');

Save and upload the wp-config.php file.

wp-cron.php is now no longer triggered by WordPress.

Running wp-cron.php with a server based cron job every 5 hours

In this example, we use Crontab to add a cron job, that will execute wp-cron.php on a fixed interval – every 5 hours in this case.

Requirements: You will need to connect to your webspace using SSH and provide the full path to your WordPress website for this cron job. Before you get started, here are some additional resources provided by the 1&1 Help Center team:

Good, let’s go! Access your webspace using SSH and start Crontab:

crontab -e

The VI-editor opens and you should see the Crontab file of the active user.

To edit the file, you have to switch to Insert Mode by pressing i.

Enter the following lines to set up a cron job that will run every 5 hours, every day of the week:

MAILTO=john.smith@example.com
# MAILTO sends e-mail notifications with error reports / optional but recommended
0 */5 * * * /usr/bin/php5.5-cli /full_path_to_your_website/wp-cron.php

Change /usr/bin/php5.5-cli to match the PHP version that is active for your domain and replace  /full_path_to_your_website with the actual path to your website.
Learn more: Setting the PHP version for your domain.

The schedule format explainded

Field: Minute / Hour / Day of Month / Month / Day of Week
Example0 / 5 / * / * / *
Description: 0 minutes past the hour / of the 5th hour / every day / of every month / every day of the week

Switch from Insert Mode to Command Mode by pressing Esc. It is time to save your changes and close the VI-editor:

:wq

wp-cron.php will now be triggered every 5 hours.

You might also like:

Here are some additional resources provided by the 1&1 Help Center team:

 

 

 

Please rate this post :