Table of Contents
Table of Contents
Cron is a standard Unix-like/Linux utility, and it is quite possibly the most valuable highlights which plan content or order to be executed consequently at a predefined date and time. The booked orders, contents, and undertakings are called Cron Jobs. This element was acquainted with mechanizing the cycle of monotonous undertakings.
WordPress utilizes a record called wp-cron.php as a virtual cron work or planned errand to computerize things like distributing booked posts, checking for module or topic refreshes, sending email warnings, and then some.
In WordPress, this is taken care of by WP-Cron, which is utilized to reenact a framework cron. Notwithstanding, contingent upon the measure of traffic to your site, on low traffic locales this is completely fine, yet when your web page visits begin to increment, checking on numerous occasions for booked errands can be extremely wasteful and lead to asset use issues for the worker, this will thus make your site load more slowly. So doing this will free up a lot of resources and make your wordpress site load faster.
wp-cron job is used to keep your website running smoothly. Cron job is a job scheduler. it is used for check software updates, schedule posting, send trackback pings etc
If the cron job is not running properly important background tasks will not run. it could find that your WordPress installation is out of date and full of security vulnerabilities.
wp-cron.php
In WordPress, tasks like scheduling are managed by WP-Cron, which simulates a system cron. However, as your site traffic increases, relying on WP-Cron can negatively affect page load times. To optimize performance, we’ll show you how to disable WP-Cron (wp-cron.php) and replace it with a system cron job for better efficiency.
WordPress has a built-in script >> wp-cron.php. wp-cron.php runs only when HTTP requests to the server someone visits your blog the server spawns a process to run cron jobs.
If the blog is new, and nobody comes to visit the site? Well. the cron jobs will not run automatically which could lead to problems over time.
If a blog is established and gets a lot of visitors then each wp-cron.php spawns a process on your server, it could lead to excess server load and ultimately waste your server resources.
Before we set up the WordPress cron job in our Linux server, you should disable the internal WordPress cron job Process. Add one line to your wp-config.php. Open your wp-config.php file and add the line
define(‘DISABLE_WP_CRON’, true);
We can add the WordPress cron job to our Linux server. If you don’t have `crontab` installed, use the commands below to install it.
Update your package list using update command using apt update
sudo apt-get update
Install cron
sudo apt-get install cron
it will be asked if you are sure you want to install cron, type Y and hit Enter to continue.
Add the WordPress Cron Job to Linux Server
we can add the WordPress cron job in our Linux Server
crontab -e
add the below line to crontab.
*/15 * * * * cd /var/www/html; php /var/www/html/wp-cron.php > /dev/null 2>&1
Replace /var/www/html with the correct path to the wp-cron.php. This command will run WordPress cron jobs once every 15 minutes. save and exit
After save cron job it should automatically begin processing the background tasks on a regular basis, without creating an unnecessary drain on server resources