-
-
Notifications
You must be signed in to change notification settings - Fork 1
Crontab syntax
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.
* * * * * hello
0 * * * * printf 'Top of the hour\n'
30 9 * * 1-5 App\Task\Digest::send
0 0 1 * * php bin/monthly-report.php
Blank lines are ignored.
Lines beginning with # are also ignored:
# This is a comment.
*/10 * * * * hello
The field parser supports the usual cron building blocks:
-
*for "any value" -
1,3,5for a list -
9-17for a range -
*/15for a step -
1-10/2for 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 fields may use short English names:
0 22 * JAN MON-FRI hello
Supported month names:
JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
Supported weekday names:
MONTUEWEDTHUFRISATSUN
The library also accepts these nickname expressions:
@yearly@annually@monthly@weekly@daily@hourly
Example:
@daily App\Task\Cleanup::run
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.
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.
To check syntax without running anything:
vendor/bin/cron --validateIf the file is valid, the command prints Syntax OK with the resolved file path.
To list each job with a plain-English explanation of when it runs:
vendor/bin/cron --explainFor 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 AMEvery 10 secondsAt 09:00 AM, only on Monday, Wednesday and FridayAt 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.
PHP.GT/Cron is a separately maintained component of PHP.GT/WebEngine.