WP-Cron Control

IN Marketing & Wordpress
What is WP-Cron?

WP-Cron is used by WordPress & plugins to run all the automatic tasks, like scheduling a backup, or posting pingbacks and trackbacks, sending emails (like when you get comments or someone registers), scheduling posts, etc.

But, as more WP-Cron instances are launched, and some instances running at the same time, it can cause problems on your server.

Wp_cron is called each time a page is loaded on your site, so depending on the amount of traffic you get, it could be running hundreds of thousands of times per day. Not only that, but some “cron jobs” take a few minutes to complete which can cause processes to all be active at the same time, and running over and over again.

The more traffic you have, the more resources and processes are being run constantly on the server, and if you are on a shared host (the majority of people fall into this category), you risk your host taking an issue with your cron-jobs as it consumes the shared cpu resources.

Why I use WP-Cron Control
Instead of wp-cron loading every time I get a visitor, which makes my host “crazy mad”, I turn off wp-cron in the backend and run it manually from a cron-job within cPanel. I can setup cron jobs to run depending on what I want, if a site is updated regularly or has a lot of scheduled tasks, I can set the cronjob to run as low as 15 minutes, but I generally choose once or twice a day or every 2 hours. This makes the wp-cron.php file run a lot less, and keeps my host happy.It might help you if you don’t get much traffic and want to force cron to run, so if you have the opposite problem of “not enough visitors”, then this plugin will help too. This plugin is out-dated, and a little bit buggy, but there doesn’t seem to be any alternatives out there – if you know of one, please let me know.

How I use WP-Cron Control

First, I disable wp-cron from running on every page load by modifying the wp-config.php file and adding this line near the top:

[snippet id=”240″]

Add a comment to your wp-config.php file

I also usually add // Penny – REASON WHY as a comment to the end of anything I change in config files.

I do this out of habit so that I can “notice” anything in future that I might of forgotten that it was me that changed it.

So for the above example, I actually used:

define(‘DISABLE_WP_CRON’, true);     // Penny – Disabled WP_Cron and setup manual cron job in cpanel

I recommend you do the same, it also helps if you ever have someone else manage your site, they can see what you did and the reason why you did it, to know whether it’s still needed or not.

Then you install WP-Cron Control per normal (install/activate) which will give you a custom cronjob to add to your cronjobs in cPanel.

wp cron controls settings

Note: In the above screenshot, I have the 2nd option unchecked, but you will probably want to check that box. The above site is for my “problem site” so I have as much as I can “switched off” to save site resources in any way I can.

Then you need to setup a manual cron job (in your cPanel) that is set to schedule for times that are under your own control about how often it runs.

cronjobs

Minimum should be 15 minutes, but you can set it for hourly, twice a day, 24 hours, etc. It all depends on what “automatic” things you have scheduled on your particular install as to how often it should be run.

(But no shared host is happy with less than 15 minutes, so if you are doing this to keep your host happy, at least make it 15 minutes or more. If you run a site like buddypress, etc, then you need to make it much lower, than a more static site like a blog that you update every few days – because buddypress (and things like it) have people “talking” to each other, uploading photos and writing in forums, etc, and cron jobs are needed to run for each update – so to keep your members happy, you’ll want to make it as low as you possibly can, but to keep your host happy, you’ll want to make it as high as you possibly can)

 

add new cron

Just paste the command from WP-Cron Control directly into the command in your cron jobs, and click on — Common Settings — and choose a time from that – that’s the fastest, easiest way to setup a cron job.

And now you are done.

Check upcoming cron schedules from within wordpress

To check what you have upcoming in your cron schedule, you can optionally install the plugin “WP Crontrol“. This plugin will let you see from your wordpress backend, exactly what cron jobs are setup and when they are scheduled to run.

wp-crontrol

 

Penny (PennyButler.com)
Penny (PennyButler.com)

Who are we? What are we doing here? What is the meaning of life? Penny is a truth-seeker, ever-questioning, ever-learning, ever-researching, ever delving further and deeper down the rabbit hole. This site is a legacy of sorts, a place to collect thoughts, notes, book summaries, whilst providing a searchable archive to easily lookup and reference.

Leave a Reply

Your email address will not be published. Required fields are marked *