Replace wordpress cron with a real cronjob

WordPress comes with its own cron job that allows you to schedule your posts and events., WordPress cron is a system that has a set of tasks, each with a time when it needs to be executed.

However, in some cases, wp-cron.php file in your main WordPress may become target of a DOS attack, or caching plugins can interfere with its execution which can cause a lot of server load and as a result the cron can not execute properly and timely. That’s why, you can alternate this file constant execution with a real cron job.

Replacing your WordPress cron job with a server cron job can be beneficial in many ways.By using a real cron job,You can be sure that all your schedule tasks are executed  It can eliminate high CPU usage caused by WordPress. For blogs with high traffic, using a real cron job can also reduce the server bandwidth and reduce the chances of your server crashing.

To configure a real cron job First, You need to disable the WordPress cron job by opening your wp-confg.php file and add this line at the end, before the closing ?>tag:

define('DISABLE_WP_CRON', true);

Once done , you need to setup a real cron job and execute this file with it.

Log into your cPanel.

Scroll down the list of applications until you see the “cron jobs” link. Click on it.

Then, add the following command to be executed every 30 minutes:

/usr/local/bin/php /home/user/public_html/wp-cron.php

Or you can also use wget as an alternate:

wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

You need to replace /user/ with your actual cPanel username. The Cron jobs tool has some of the most common schedules preset, so you can just select Every 30 minutes from the minutes drop-down and place a * symbol in the others.

That’s it.

If you want you can also set an email to receive the output of your cronjob, to make sure that the task is executing properly.