Skip to content

Crontab syntax

Greg Bowler edited this page May 17, 2026 · 2 revisions

This library reads a standard five-field crontab schedule at the start of each line:

* * * * * command
| | | | |
| | | | +-- day of week
| | | +---- month
| | +------ day of month
| +-------- hour
+---------- minute

The command starts after the fifth field.

Basic examples

* * * * * hello
0 * * * * printf 'Top of the hour\n'
30 9 * * 1-5 App\Task\Digest::send
0 0 1 * * php bin/monthly-report.php

Comments and blank lines

Blank lines are ignored.

Lines beginning with # are also ignored:

# This is a comment.
*/10 * * * * hello

Lists, ranges, and steps

The field parser supports the usual cron building blocks:

  • * for "any value"
  • 1,3,5 for a list
  • 9-17 for a range
  • */15 for a step
  • 1-10/2 for a stepped range

Examples:

*/15 * * * * example("every 15 minutes")
0 9-17 * * 1-5 example("every hour from 9 through 17, Monday through Friday")
0 8,12,18 * * * example("hour 8, 12, and 18")

Month and weekday names

Month and weekday fields may use short English names:

0 22 * JAN MON-FRI hello

Supported month names:

  • JAN
  • FEB
  • MAR
  • APR
  • MAY
  • JUN
  • JUL
  • AUG
  • SEP
  • OCT
  • NOV
  • DEC

Supported weekday names:

  • MON
  • TUE
  • WED
  • THU
  • FRI
  • SAT
  • SUN

Nicknames

The library also accepts these nickname expressions:

  • @yearly
  • @annually
  • @monthly
  • @weekly
  • @daily
  • @hourly

Example:

@daily App\Task\Cleanup::run

Day-of-month and day-of-week behaviour

Cron has one important rule that often surprises people: when both the day-of-month and day-of-week fields are restricted, they use OR semantics.

For example:

0 12 13 * FRI hello

This runs at noon on:

  • every 13th day of the month
  • every Friday

It does not require both conditions to match at the same time.

Second-precision extension

This library adds one non-standard extension: the first field may use an s suffix to mean seconds within the matching minute.

*/10s * * * * hello

That expression runs every 10 seconds.

This is useful for local development, short-running workers, or projects where minute precision is not enough.

Validating a file

To check syntax without running anything:

vendor/bin/cron --validate

If the file is valid, the command prints Syntax OK with the resolved file path.

Explaining a file

To list each job with a plain-English explanation of when it runs:

vendor/bin/cron --explain

For example, this crontab:

@DAILY App\Task\Backup::run
*/10s * * * * hello
0 9 * * MON,WED,FRI App\Task\Digest::send
05 01 * MAY SUN#2 App\Task\Maintenance::window

produces explanations such as:

  • At 12:00 AM
  • Every 10 seconds
  • At 09:00 AM, only on Monday, Wednesday and Friday
  • At 01:05 AM, on the second Sunday of the month in May

This is useful when reviewing a new schedule, checking unfamiliar syntax, or confirming that a line means what we think it means before running it.


Now that the schedule format is clear, continue with Running the runner.

Clone this wiki locally