How to Replace the WordPress Cron with a Real Cronjob
Learn how to setup a real cron job for your WordPress sheduled tasks
Because WordPress has to work on all sort of different platforms, OS's and configurations, it can't rely that there will be a cronjob service on the server that can handle scheduled tasks. This is why WordPress developers have created a workaround - the wp-cron.php file in your main WordPress folder is hit every time someone loads a page. It then checks if there's a scheduled task to be done and executes it if necessary.
However, in some cases, this file may become target of a DOS attack, or caching plugins can interfere with its execution which can cause either a lot of server load or the scheduled tasks may not execute properly and timely. This is why, you can substitute this file constant execution with a real cron job.
First, you need to disable the file to be hit every time someone loads your pages. To do this, open the wp-config.php file in your main WordPress folder and add this line at the end, before the closing ?>tag:
Once you do that, you need to setup a real cron job and execute this file with it. You don't want to trigger it too often - 30 minutes should be fine for most of the websites. To do this, login to your cPanel and go to the Cron jobs tool located in the Advanced tab.
Then, add the following command to be executed every 30 minutes:
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 mintues from the minutes drop-down and place a * symbol in the others.
If you want to, you can set an email to receive the output of your cronjob. We recommend you doing that, to make sure that the task is executing properly. Once you get an email with the wp-cron.php output, you can remove your email address from the field to stop getting those mails.
No comments :
Write comments