Urgent.News

What's breaking now, across thousands of outlets.

Tech

Crontab syntax basics, and how it differs from WP-Cron

"What does */5 * * * * actually mean?" — anyone setting up a scheduled task on a server has probably stared at that row of asterisks at some point. If you run WordPress, you may already be familiar with inspecting WP-Cron's internals through WP-CLI , but the actual crontab syntax used by the OS itself is something many people never learn properly. Before you can switch WP-Cron over to a real…

Crontab syntax is a scheduling mechanism built into Unix-like systems such as Linux and macOS. The term is short for "cron table," which is a configuration file used to list what to run and when, with each line consisting of five time fields followed by the command to execute. Each field represents a specific time unit: minute (0-59), hour (0-23, 24-hour clock), day (1-31), month (1-12), and weekday (0-7, where 0 and 7 both represent Sunday).

A wildcard "*" can be used to signify every value for a field, meaning that a line where all five fields are "*" will run at any time.

Some common patterns include:

- Running something every minute: * * * * * command

- Running something every 5 minutes: */5 * * * * command

- Running something daily at 3:00 AM: 0 3 * * * command

- Running something at 9:00 AM on weekdays (Monday to Friday): 0 9 * * 1-5 command

- Running something at midnight on the 1st of every month: 0 0 1 * * command

The slash notation in */5 is known as a "step value," indicating that the minute 0 will be incremented by 5 each time. The hyphen in 1-5 represents a range, which will include all the values from 1 to 5 (Monday to Friday). Specific values can also be listed using commas, such as 1,3,5. Once you're comfortable with these combinations, you should be able to express most schedules.

OS-level crontab entries are managed using the command "crontab -e" and can be listed with "crontab -l". To remove the entire crontab, use "crontab -r". It's good practice to first run "crontab -l" to confirm what changes you're about to make, as "crontab -r" will wipe everything out at once.

Jobs run by cron have a minimal PATH environment variable compared to a user's interactive login shell. A command that works fine when typed manually may fail with "command not found" when executed by cron. To prevent this, specify the full path to the command being executed. For example, replace "wp cron event run" with "/usr/local/bin/wp cron event run" in the crontab entry.

WP-Cron, on the other hand, is a scheduling mechanism built into WordPress. Unlike OS-level crontab, WP-Cron does not run on a fixed schedule but instead checks for overdue tasks every time a page is loaded in WordPress. This design is often referred to as a "pseudo-cron" because it depends on website traffic. A scheduled task may fail to execute on time if a website receives low traffic, particularly during off-peak hours.

To overcome this limitation, you can switch to an OS-level crontab entry that periodically invokes WP-CLI to run WP-Cron tasks.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Beyond Clean Architecture: The Iceberg Pattern for Real-Time Flutter Apps with BlocSignal

Why Traditional Clean Architecture Stalls in Real-Time Cloud Apps Most enterprise Flutter tutorials preach Uncle Bob's Clean Architecture or classic BLoC layering.

  • Iceberg Pattern introduces four-layer architecture for real-time Flutter apps
  • Presentation Layer handles UI rendering and user interactions synchronously
  • Domain Engine and Cache layer manages asynchronous cloud streams and data normalization

More from Saturday 5 September →