Making WordPress faster by running wp-cron with Linux

Making WordPress faster by running wp-cron with Linux

WordPress use wp-cron to check updates for themes, plugins and some other process but it could have an impact on your website speed because WordPress execute it on every page-loading. So if you have a lot of traffic, it will (no benchmark proof at the moment) delay page loading for users.

So if you are using a linux server (VPS or dedicated), you can easily create a cron job to run it each 5 minutes or each 10 minutes. But remember WordPress need wp-cron to work properly, so don't disable it  totally !

To disable wp-cron, just add the following line in wp-config.php :

define('DISABLE_WP_CRON', true); 

Then to add a cronjob you have to a :

## Run the crontab with your server or vhost user 
crontab -u yourserveruser -e

## method 1 : using curl to run the script
*/10 * * * * curl http://example.com/wp-cron.php > /dev/null 2>&1

## method 2 : using php to run it
*/10 * * * * cd /var/www/example.com/htdocs; php /var/www/example.com/htdocs/wp-cron.php > /dev/null 2>&1

The first method use PHP-CGI when the second use PHP-CLI, the only difference is CLI does not have time limit to run a script.
Because this way, the wp-cron will not impact page loading speed, it's highly recommended to use linux cron instead of default WordPress cron.

You can change */10 with */5 to run the cron each 5 minutes instead of each 10 minutes.