Currently Available: Need a skilled Software Developer for your next project?
Categories
WordPress

How to Run WordPress Scheduled Tasks with System Cron on a Low-Traffic Site

WordPress uses WP-Cron, its built-in scheduler, to run tasks such as publishing scheduled posts and checking for updates. By default, a page visit triggers WordPress to check for tasks that are due. On a low-traffic site, long gaps between visits can leave those tasks waiting.

A server’s system cron scheduler runs commands at set intervals, even when nobody visits the site. To use system cron with WordPress, disable the page-visit trigger and have system cron request WordPress’s wp-cron.php file at regular intervals. WordPress then gets regular chances to run tasks, as long as each request reaches the site and finishes.

Why low traffic delays WP-Cron

WordPress checks its scheduled tasks when a request triggers WP-Cron. When nobody visits the site, WordPress may not check whether a task is due, so scheduled posts can publish after their intended time and other scheduled work can run late. Caching can further complicate page-triggered checks, as RunCloud’s explanation of WP-Cron describes.

WP-Cron schedules tasks using intervals, while system cron follows the server’s clock and runs commands on a set schedule. A system cron request gives WordPress regular opportunities to run tasks even when site traffic is sparse. The request does not promise that every task finishes at an exact minute; it prompts WordPress to process tasks that are due.

Disable the page-visit trigger

Before adding a system cron job, add this line to wp-config.php, the configuration file in the WordPress installation directory:

define( 'DISABLE_WP_CRON', true );

Place it before the comment that says That's all, stop editing! if that comment appears in the file. This setting stops WordPress from launching its scheduled-task check on page visits. It does not schedule a replacement, so add and test the system cron job before relying on scheduled posts or other recurring tasks. WordPress hosting providers such as DreamHost document this setup.

Schedule requests to wp-cron.php

Add a cron entry through your hosting control panel’s cron-job feature or, where available, with the server’s crontab. Each crontab entry, a scheduled command on the server, starts with five fields. They specify, in order, the minute; hour; day of the month; month; and day of the week. The command follows.

For example, this entry requests the WordPress cron file every five minutes:

*/5 * * * * wget -q -O - 'https://example.com/wp-cron.php?doing_wp_cron' >/dev/null 2>&1

Replace example.com with your site’s hostname. The command uses wget to make an HTTPS request. -q -O - suppresses progress messages and sends the response to standard output, which the final redirection discards along with error messages. Confirm that your host provides wget. If it does not, use an HTTP request method supported by that host or follow its cron-job instructions.

The right interval depends on how quickly your scheduled tasks need to run. Five minutes is a reasonable starting point when publishing delays matter; a longer interval means tasks can wait longer for the next request. Hosting recommendations vary: for example, DreamHost suggests a 15-minute schedule, while other setups use shorter intervals. Choose an interval your host supports and that fits your site’s scheduling needs.

Check that scheduled tasks run

After adding the cron entry, confirm that the scheduled command reaches your site. If you suppress all output as in the example, temporarily remove -q and the output redirection while troubleshooting so you can see request errors. Then check whether a scheduled post publishes as expected or whether other scheduled work completes.

If you have WP-CLI, WordPress’s command-line tool, you can inspect and test cron events from the server. Run wp cron event list to view scheduled events. The wp cron test command reports an error when DISABLE_WP_CRON is true. It checks WordPress’s automatic cron trigger, so it does not verify your system cron job. The command wp cron event run <hook> runs events associated with a specific hook, a named event identifier used by WordPress or a plugin. Use that command only when you know which hook you intend to run.

A direct command-line run of wp-cron.php can behave differently from an HTTP request because some plugins rely on web-request variables or mail settings. An HTTP request to wp-cron.php avoids that particular difference. The trade-off and plugin concerns are discussed in this WordPress Stack Exchange thread.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

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