How to work Cron Jobs Dependably

May 9, 2020

What is a cron job, and how do they work with Penguin Hosting/The Image Stop ltd.

A cron job is a server-side task that schedules a job to run at a specific time or repeating interval. Cron jobs exist to help automate repetitive tasks or to schedule a task to run in the future – it’s like having an extra set of hands (so your actual hands are free to do something fun, like eat tacos!)

For example, you can schedule a repetitive task to back your site up nightly at 1:00 AM, or you can have a task that only runs once to publish a blog post at 4:15 PM next Tuesday.

Cron jobs at Penguin Hosting/The Image Stop ltd.

In most of our hosting packages, don’t allow users to create or manage cron jobs at the server-level, since this would require a higher level of access to the servers that we limit for security reasons. Good news though, WordPress has its own built-in robust task scheduling system called WP Cron, and you can tap into this awesome functionality to manage existing jobs or create your own!

Cron jobs with WordPress

WordPress is already using WP Cron behind the scenes for many things, like publishing scheduled posts, checking for updates, and general maintenance. Plugins will also create their own WP Cron jobs automating some of their tasks. For example, the WooCommerce plugin creates jobs for things like reoccurring subscription payments.

NOTE

The main difference between a server cron job and a WordPress cron job is that WP Cron does not run autonomously at the server-level. WP Cron is triggered when a page is loaded by a visitor of your site. On every page load, it checks a list to see if any scheduled tasks should be running right now and starts those jobs. This is potentially a limitation, but we’ll explain the slick workarounds available below!

Limitation of WP Cron : Low-traffic sites

If you have a low-traffic site, it might not get enough visitors to run jobs at the time they’ve been scheduled.

For example, if a task is scheduled to run at 10 AM, and nobody visits the site until 11:37 AM, that job will be running later than it was scheduled, since there wasn’t a page load to trigger WP Cron. However, you can easily get around this by creating a free account with an external cron service!

The solution, External Cron!

You can use an external cron service to ping the WordPress cron system at a regular interval, like once every 15 minutes, running the jobs that are currently due.

There are a couple of free services you can use to do this.

  • cron-job.org – (Free up to 1 request per minute)
  • EasyCron – (Free up to 2–3 requests per hour)

You need to set the external service to ping your site’s wp-cron.php file.
If your site was “myflysite.com”, you would set it to ping: https://myflysite.com/wp-cron.php

NOTE

New staging sites are Privacy Mode enabled by default. Privacy Mode blocks public traffic from reaching your site, and because WP Cron runs on page load, it will not work if you have Privacy Mode enabled. When you take your site live and disable Privacy Mode, WP Cron will start working as expected.

Managing and creating WP Cron jobs

So, how do I go about creating and editing cron jobs, you might ask? Well, there are a number of plugins that will allow you to interact with WP Cron jobs. The most recommended one is the WP Crontrol plugin. WP Crontrol allows you to see what jobs are already running on your site, adjust how often they run, as well as create your own WP cron jobs.

Need Help?

Reach out to your PenguinHosting/The Image Stop ltd. representative and we’ll be more than happy to assist you in setting things up. 🙂

Want other info? Send us your suggestion and we'll work on providing a new blog 🙂

Contact iS

Contact us anytime. We appreciate meeting our clients and discussing their Design and Marketing ideas. Please use our Online Booking button in our navigation menu or send us a note here.

Office: 403.630.3409


Mailing Address: 47 Cedarbrook Close SW Calgary, Alberta T2W 5B8

Business Hours: 8am – 4:30 pm, Monday to Friday (MST)