How to Disable WP-Cron for Faster Performance
Last updated
Last updated
CRON jobs are used to schedule tasks at periodic fixed times, dates, or intervals on your WordPress site. Some examples of a WordPress cron job might involve scheduling a post to publish, checking for updates, or a backup plugin running on a predefined schedule.
In WordPress, this is handled by WP-Cron, which is used to simulate a system cron. However, depending on the amount of traffic to your site, using the built-in cron handler can actually start to impact your page load times. So today we’ll show you how to disable WP-Cron (wp-cron.php) and instead use a system cron for faster performance.
We deal with a lot of high-traffic and demanding sites at WeWP. Because of this, we’ve seen a lot of performance issues with the WordPress built-in cron handler: WP-Cron. First off, it’s important to understand that WP-Cron is not a real cron job; it’s simply what WordPress has created to mimic what a system cron does.
WP-Cron does not run continuously. By default, the wp-cron.php fires on every page load, which on high-traffic sites can cause problems. If a site doesn’t have enough PHP workers, sometimes a request will come in, WordPress will spawn the cron, but the cron has to wait for the worker, and therefore just sits there.
The reverse scenario is also true. If a site doesn’t have a lot of traffic, schedules could be missed due to the fact that no one has loaded a page.
A better approach is to disable WP-Cron and use the system cron instead. This runs on a predefined schedule and is even recommended in the official Plugin handbook.
To disable WP-Cron, add the following to your wp-config.php file, just before the line Note: This disables it from running on page load, not when you call it directly via wp-cron.php.
define('DISABLE_WP_CRON', true);
Now that WP-Cron is disabled, you need to set up a system cron job to handle the scheduled tasks. The steps vary depending on your hosting environment. Below are the steps for a typical Linux-based server.
For SSH Users
Access Your Server via SSH: Use an SSH client to connect to your server.
Open the Crontab File: Run the following command to open the crontab file for editing:
crontab -e
Add the Cron Job:
To run the cron job every 15 minutes, add the following line to the crontab file (replace /path-to-your-site/ with the actual path to your WordPress installation):
*/15 * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Save and Exit: Save the crontab file and exit the editor.
After setting up the cron job, it's essential to verify that it's working correctly.
Check the Logs: Monitor your server logs to ensure that the cron job runs without errors.
Scheduled Tasks: Verify that scheduled tasks such as publishing scheduled posts and updates are executed as expected.
Disabling WP-Cron and replacing it with a system cron job can significantly improve your WordPress site's performance, especially on high-traffic sites. By following the steps outlined in this guide, you can ensure that your scheduled tasks are handled efficiently, leading to a faster and more reliable website.
Optimize Database: Regularly optimize your WordPress database to keep it running smoothly.
Use Caching: Implement caching solutions to reduce server load and improve page load times.
Monitor Performance: Use performance monitoring tools to keep an eye on your site's performance and address any issues promptly.
By taking these steps, you can ensure that your WordPress site remains fast and efficient, providing a better experience for your visitors.