Replace WordPress Cron With Linux Cron

WordPress has a built int cron feature that will allow the overall platform and for plugins to run tasks. By default, this cron will be triggered based on user visits. If a user visits the site, the cron will be checked and if a task is due to be executed, it will run and perform whatever task it has been instructed to run. This is generally quite good but the cost of this check still falls on the user that visits the website.

Why would you disable WordPress cron?

If you have a low volume website, the cron tasks may not run due to a lack of visits to the website. You may want to keep plugins up to date and make sure other critical things are kept up to date. This won’t work well if people are not visiting the site to trigger the cron jobs.

On the other end of the scale, if you have a very high volume website, you will have many visitors per second. It is a waste of computing power to have every single visitor be responsible for checking whether cron tasks need to run.

On the other side, we all use cache plugin these days. Bigger sites might even use a reverse proxy. These cache hits will never hit the WordPress code and as a result, will not have the chance to check if cron needs to run. You could get 10’000 hits in an hour and if all of them are cache hits, WordPress’s PHP code will never execute and as a result, cron will not run.

The solution to both of these problems is the same. Disable the default WordPress cron behaviour and make use of the baked-in cron system that comes with all Linux servers.

How To Disable WordPress Cron

Disabling cron is pretty simple. Go to the wp-config.php file in the root of your WordPress install and add the following line of code. This will turn off the default cron functionality.

define('DISABLE_WP_CRON', true);

At this point, no more cron tasks will be executed until you update your Linux crontab to perform the call. The line of code below should be added to your cron files. This is normally found in /etc/crontab but may vary depending on what flavour of Linux you are using.

This entry will make a call to the WordPress cron system every 15 minutes, which is what the default is for WordPress already. You can increase or decrease this as often as you like.
*/15 * * * * root php /var/www/nerdpress/wp-cron.php >/dev/null 2>&1

Advantages of Using Linux Cron For WordPress

The main benefit of using Linux cron for WordPress is a big increase in efficiency. Linux cron is a battle-hardened system that is incredibly efficient. Your operating system will already be using and running this so the extra cost of adding an additional line is very small. The processing will only be performed when needed.

From the PHP side, when a user visits your website, no processing time will be spent checking whether the WordPress cron needs to run. Linux will run it every 15 minutes and no wasted processing will be performed. For very high and very low volume websites, this is one of the best things you can do to squeeze a little more juice out of your web server.

Related Articles

Related Questions

Feeling Trapped as a Front-End Developer Forced into DevOps

Hey everyone! I've been a front-end developer for 11 years, and while I've been doing a bit of full-stack work, I've recently been pushed...

How Can Beginners Start Earning Money with Programming?

Hey everyone! I've recently jumped into the world of programming, and it's quite a shift from my previous field. I've always been interested in...

Why Can’t My Parents’ Old LCD TVs Play Movies from USB?

I'm trying to get some movies into a USB drive to share with my parents, but they have older LCD TVs that aren't smart...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Erase Gemini Nano Banana Watermark

Below is a simple content eraser tool. It works very similar to the content aware fill tool that is used in Photoshop. You can...

Keep Your Screen Awake Tool

This simple online stay awake tool prevents your computer screen from going to sleep while you have this page open. It runs entirely in your...

Neural Network Simulation Tool

The Neural Network Visual Builder is an interactive, client-side tool designed to demystify deep learning. It allows users to drag-and-drop neural network layers to...

Ray Trace Simulator – Interactive Optical Ray Tracing Tool

This ray trace simulator lets you visualise how light rays move through an optical system in real time. You can trace beams as they...

Interactive CPU Architecture Simulator

This is an Interactive CPU Architecture Simulator that provides a hands-on, visual learning experience for understanding how a processor executes code. It models a...

AI Image Upscaler

Our AI Image Upscaler allows you to upload any image and instantly increase its resolution using advanced upscaling models. Choose between 2x, 3x or...

Latest Posts

Latest Questions