cronScheduleGap.php
Table of Contents
Functions
- cronScheduleGap() : int|null
- Measures the longest time a cron expression can leave between two runs.
Functions
cronScheduleGap()
Measures the longest time a cron expression can leave between two runs.
cronScheduleGap(string $expression) : int|null
The number a "this job has not run for too long" check needs, and deliberately the longest
gap rather than the average or the nominal period. 30 2 * * 1-5 runs five times a week, which
averages to 33 hours; what matters is that it leaves 72 hours across the weekend, because a
shorter threshold would alert every Sunday on a job behaving exactly as configured — and an
alert that cries on a working setup is an alert people turn off.
Computed by laying out one cycle rather than by recognising presets: every run in a day, a week or a month — depending on which fields are restricted — and the widest interval between two consecutive runs, wrapping around the end of the cycle. A restriction on the day of the month is read on a 31-day cycle: the pessimistic reading, since a job on the 31st skips the months that have none.
Returns null for a schedule it will not guess at:
- a field cronFieldValues() cannot read, or not exactly five fields;
- a month restriction — a yearly schedule, whose gap depends on the year;
- a restricted day of the month and a restricted day of the week: cron then runs when either matches, which is not a cycle this measures.
Parameters
- $expression : string
-
The five standard fields: minute, hour, day of month, month, day of week.
Tags
Return values
int|null —The longest interval between two runs, in seconds; null when it is not known.