logomichael sumner
Contact

Why Use an External Cron Job, Not WordPress Cron Job

What Is a Cron Job?

A cron job is a task to be performed at a given time.

An event has to execute the action.

So that event can be through a certain time reached, or if someone/something executes the file themselves.

You’ll find other ways to call a cron job.

Like as a:

  • Cron Scheduler, or as a
  • Scheduled Task

The word ‘cron’ is meant to be from the Greek word ‘chronos’ meaning time.

So you might get the point why they called it ‘cron’.

It’s much cooler to call it that way as ‘cron’, and uses 1 less character — that’s all.

WordPress comes with its own cron scheduler, through the file wp-cron.php, and the functionality of this is found in the /wp-includes/cron.php file.

Why Not to Use a WordPress Cron Job?

Without diving too deep into why it’s not the best idea to use the WordPress Cron Job, it’s simply the way it has to work.

Since it’s a file, something/someone has to regularly visit your website as the event to run the WordPress Cron.

Say if you’d have a plugin that’ll run itself at 10pm, but you’ve got no visitors on your website at that time, then no cron jobs will run at 10pm.

And if you were like me scheduling backups in the evening thinking it’s best when there are no visitors — sorry to put you in the wrong corner!

Because instead of scheduling a WordPress backup, why not do scheduled server backups instead? They’re more reliable anyway as they wouldn’t need visitors to your site. Since the event will be the server time instead.

Benefits of Using an External Cron Job

You might be thinking of alternatives to the WordPress Cron Job.

Since there’s got to be another way as it’s obvious that there are many websites that won’t have visitors every second.

The solution is to use External Cron Jobs.

I’ll give you the pros and cons later with this compared to the ‘server’ cron jobs.

Using an External Cron Job, you’ll be able to schedule a task using another server than your own — thus the word external.

This is highly recommended since it’s a one-size-fits-all approach especially if you don’t have server access to your website, for example.

How to Use an External Cron Job?

The External Cron Job I recommend is the open-source project called… well… Cron-job.org.

Best thing of all is that it’s completely free. And if you might have a WordPress plugin in need of cron jobs, then head over to cron-job.org, create an account or use your existing one, and setup a cron job.

Setting up a cron job on cron-job.org

If you’ve already got an account on cron-job.org, then continue to Step #3.

Step #1 On the Homepage, click ‘Signup’.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Step #2 Fill out your account details.

You should receive an email that needs verification. Open your email client and click the verification link.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Step #3 Login using your email address and password.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Step #4 Click ‘Cronjobs’ on the menu.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Step #5 You’ll find a list of all your cron jobs here.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Step #6 Click the button ‘Create cronjob’.

Why Use an External Cron Job, Not WordPress Cron Job  "decoding="async

Add a descriptive Title and the URL of the file that’ll need to be run.

Normally you wouldn’t need HTTP authentication unless the file is password protected in some sort.

Set the Schedule for how often you want the file to be run.

Notifications are usually fine as their defaults.

Click the button the very bottom ‘Create cronjob’.

And now you’ve successfully added an External Cron job that’ll run flawlessly and show you their details if any go wrong!

External Cron Job vs Server Cron Job

The difference between the two is that external cron jobs are held on a server that is not where your website resides.

Whilst server cron jobs are usually termed as such to refer to your own server’s cron scheduling system.

This is where you would have to weigh a couple factors.

  1. Do you have a reliable server to manage the cron jobs?
  2. Will you remember to move your cron jobs to another web hosting provider, might the time arrive?

Your own Server Cron Jobs are good as they are. But what concerns others is if they will remember to move over the cron jobs should you move to another server.

There are many free website migration services when you’ll be moving to another server.

But you have to make sure that your cron jobs don’t get left out!

Conclusion

The WordPress cron job does have its use cases, like when you want to run a task for a user’s convenience.

But if it is a background task — something to be run behind-the-scenes — you don’t want to place your bets on a visitor landing on your website every second.

In the case of background tasks, you will want to either setup an External cron job or a Server cron job.

Both are good as they are. There aren’t any significant downsides to having Server cron jobs. Neither would there be for an external cron job.

But with an external cron job, you are assured to keep the cron job scheduling even if your server is moved. There’s that less worry with having the cron job needing setup again. Not every server is cPanel or Plesk.


Thank you for reading! Any questions please let me know in the comments!

Check this out — 7 Ways a Custom WordPress Theme May Be Better — it’s got to be your fancy if you’re reading about WordPress cron jobs!

Have a nice day!