Replacing the WordPress cron with a server cron is a straight forward task. The pseudo cron that is included in within WordPress contains functions that helps run scheduling jobs such as:
- Checking for theme & plugin updates
- Publish scheduled posts
- Sending pingbacks
The issue with the WordPress cron is that unlike regular cron jobs, which run at specific time based on the server settings, the WordPress cron function runs every time someone visis your WordPress site. Every page load in WordPress checks if there is a need for the WordPress cron to run and if so it then tries to make a request over HTTP to the wp-cron.php file.
The reason to replace the WordPress cron is that some jobs might might take longer than others to execute and you don’t want the user requesting the WordPress page to sit there waiting. Calling the wp-cron.php via a server cron ensures the WordPress cron function runs as a separate process in the background without delaying the page load time for the user.
Disable Internal WordPress Cron
Add this piece of code to your wp-config.php file
//Disable WordPress cron function
Add cPanel Cron Scheduled Task
Add the following cron task via cPanel and remember to replace the myserver.com address with your own website URL. Schedule it to run every 15 mins or whatever time you see fit.
wget http://www.myserver.com/wp-cron.php?doing_wp_cron=1 -O > /dev/null 2>&1
If you want the server to email you ever time the cron runs then delete the “-O > /dev/null 2>&1” section.
If that cron command is not working correctly then try the following that calls the cron php file directly.
php -q /home/account-name/public_html/wp-cron.php > /dev/null 2>&1