Our scheduled importer is a critical component for maintaining up-to-date information on our site. To ensure this process is consistent and reliable, it’s important to understand the limitations of WordPress’s default scheduling system, WP Cron, and how we can improve it.
Shortcomings of WP Cron #
The WordPress built-in scheduler, WP Cron, is often mistaken for a traditional, server-level cron job, but it functions differently and is a less reliable solution for critical, time-sensitive tasks like our scheduled import.
Our importer uses the default WP Cron system for all scheduling tasks and as a result, if you are experiencing inconsistent scheduling times, this may be a direct result of the limitations with WP Cron.
The Core Problem: Reliance on Traffic #
Unlike a true cron job that runs independently at fixed, server-level times, WP Cron only executes when a visitor loads a page on the website.
This means that on sites that receive low or infrequent visitor traffic, a scheduled task might be set to run at 2:00 AM, but if no one visits the site until 8:00 AM, the task won’t run until that later time. This can cause significant delays in data imports.
For a mission-critical features like our scheduled importer, which requires a guaranteed, precise execution time, this dependency on site visits introduces a level of instability and unpredictability.
This may be alright in situations where strict scheduling is not necessary but if this is something that is important to you, take a look at the section below to dramatically improve reliability.
Improving Reliability #
In order to ensure precise scheduling in WordPress, we need to disable the WP Cron mechanism and replace it with a true server-side cron job. This will still leverage the WP Cron core architecture, however, it moves the timing/scheduling to a truly server side timer.
This server-level cron job will be configured to call the wp-cron.php file at a fixed interval (e.g., every 5 minutes), regardless of whether or not the site has traffic. This ensures our scheduled import runs on time, every time.
Important Note: This is for advanced users, who are familiar with cPanel and hosting tools. Ideally, with some limited experience with cron jobs. If you are unsure about this process, please reach out to us for guidance.
Step 1: Disable WP Cron #
First, we must prevent WordPress from running its internal cron based on site activity.
- Using a tool like File Manager (cPanel), or FTP access to edit the file directly, Locate the file named: wp-config.php, and edit it with a file editor of your choice.
- Find the following section within the file:
/* That's all, stop editing! Happy blogging. */ - Change this section as seen below:
define( 'DISABLE_WP_CRON', true ); /* That's all, stop editing! Happy blogging. */ - Save the file
- What this does: Setting the constant to true, tells WordPress core not to automatically execute wp-cron.php – This will allow us to schedule this file as a normal cron job instead.
Step 2: Set up the Server-Side Cron Job #
Next, we establish the true cron job on the web server (via cPanel) to call the wp-cron.php file at a guaranteed, regular interval.
The steps vary slightly by hosting provider, but the core task is the same: add a command to the server’s crontab. We will aim for an execution frequency of every 5 minutes to ensure prompt task execution without excessive server load.
- Log in to your hosting control panel (cPanel).
- Navigate to the Cron Jobs section, usually under the Advanced section of the cPanel interface.
- Click on Add new Cron Job and define it as suggested (5 minutes)
- Common Settings: Select “Once per five minutes“
- Or, set the schedule values manually:
- Minute: */5
- Hour: *
- Day: *
- Month: *
- Weekday: *
- Enter the command to execute and run wp-cron.php as part of this cron job. The most common way to define this is either with wget or via local path: (Pick only one)
Using wget: (Suggested)
wget -q -O - {https://yourdomain.com}/wp-cron.php?doing_wp_cron >/dev/null 2>&1 Using local PHP Path: (Advanced but sometimes preferred)
/usr/bin/php /home/{yourusername}/public_html/wp-cron.php >/dev/null 2>&1 - Click Add New Cron Job to save the changes.
This change ensures our critical scheduled importer is executed on a guaranteed, server-side schedule, dramatically improving its reliability and precision.
