Replacing WordPress CRON Job with Server CRON to Speed Up Website
Replacing WordPress CRON Job with Server CRON to Speed Up Website.
Site owners are often frustrated by slow site loading, many tricks are often used to speed up the site. The simplest thing you can do is to configure the cache, compress images and clean up database, but today I will tell you about another way how to speed up WordPress by replacing the standard wordpress cron with a server cron. To begin with, let's understand, How WordPress Cron Works?
How WordPress Cron Works?
In fact, WordPress cron is a system, which has a given list of tasks, each of which has time, when it should be done, and once or repeating.
When the time comes - or expires - WordPress cron will execute the task and continue with the list of remaining tasks..
Visitor traffic required for WordPress, to keep track of time and scheduled tasks to run with cron.
Why is WordPress Cron Not Working??
There are many reasons, on which the cron job may or may not work, or be delayed:
- Server overloaded, and as a result cron can't execute.
- Not enough or not often enough visitors visit the site.
- Error or conflict, caused by a plugin or a combination of plugins.
and so on…
Benefits of Using Server Cron Job
Replacing the default cron job in WordPress with a server-side cron job is very useful in many ways.:
- Reliable, precise cron jobs, that run on time, as expected.
- Make your WordPress site faster for your users / visitors.
- Eliminate high CPU usage, caused by WordPress.
All benefits matter, but the second advantage is especially important.
Unfortunately, when someone visits your website, and WordPress Cron has a task to run at that moment, it runs this task during the visit, by increasing the request time or even everything can end up, that the server will show a blank page to the visitor, if the task cannot be completed completely.
In this way, you are renting a cron job (cronjob) from your visitors and transfer work to the server side.
How to Replace WordPress Cron?
It's quick and easy, let me show you, how! 2 Step.
1. Disable WordPress Cron Job
Firstly, disable wordpress cron job, by opening your wp-config configuration file.php and placing the following line of PHP code in it.
1 2 3 4 |
// Поместите строку кода ниже в ваш файл wp-config.php // Определение константы в true скажет WordPress прекратить выполнение задания cron define ('DISABLE_WP_CRON', true); |
The code will simply determine, DISABLE_WP_CRON to true and WordPress will stop running cron jobs by itself, and will wait for their call.
2. Create a cron server job
Because the WordPress cron job is no longer running, you need to set up a job on the cron server to replace it. The cron server job won't actually run scheduled jobs directly, it just does the job, what your visitors have done so far. Server cron will run time and date checks on WordPress jobs, in fact, instead of visitors, your tasks will be pulled by server CRON.
Instructions for setting up a cron job on your hosting will depend on the interface of your control panel. I would say, that the most common hosting control panel is cPanel, which is currently used by most of the major hosting companies, I don’t like this panel for its holey and skewness, but it’s easier to show on what is familiar to most.
So login to your cPanel and go to Advanced > Cron Jobs.
Then in "Add new cron job» (Add New Cron Job) here you can create a cron job. I recommend that you use the interval from 5 before 15 minutes depending on your website and, what does he do. Use the "General Settings" drop-down menu, to select interval for cron job.
The best command to use, PHP but you can use others, similar commands, if you prefer to change it. Here is the command, which we used in the picture:
php -q /home/username/public_html/wp-cron.php
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.