Documentation

Cron
in package

Cron class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
3.0.0

Table of Contents

Properties

$daysOfTheMonth  : array<string|int, mixed>
Days of the month
$daysOfTheWeek  : array<string|int, mixed>
Days of the week
$gracePeriod  : int
Grace period, in seconds, allowed between the scheduled time and the evaluation of it. Defaults to -1, i.e. the seconds value is disregarded and the schedule is due for the whole of its matching minute.
$hours  : array<string|int, mixed>
Hours
$minutes  : array<string|int, mixed>
Minutes
$months  : array<string|int, mixed>
Months
$schedule  : string|null
Schedule string
$seconds  : array<string|int, mixed>
Seconds - Not a standard cron unit of time. The smallest time interval supported by cron is 1 minute.

Methods

__construct()  : mixed
Constructor
__toString()  : string
To string method
between()  : Cron
Set job schedule to between two hours
create()  : Cron
Factory
daily()  : Cron
Set job schedule to daily (alias to hours)
dailyAt()  : Cron
Set job schedule to daily at specific time, i.e. 14:30
evaluate()  : bool
Evaluate the set cron schedule value against a time value
every10Minutes()  : Cron
Set job schedule to every 10 minutes
every10Seconds()  : Cron
Set job schedule to every 10 seconds
every15Minutes()  : Cron
Set job schedule to every 15 minutes
every15Seconds()  : Cron
Set job schedule to every 15 seconds
every20Minutes()  : Cron
Set job schedule to every 20 minutes
every20Seconds()  : Cron
Set job schedule to every 20 seconds
every30Minutes()  : Cron
Set job schedule to every 30 minutes
every30Seconds()  : Cron
Set job schedule to every 30 seconds
every5Minutes()  : Cron
Set job schedule to every 5 minutes
every5Seconds()  : Cron
Set job schedule to every 5 seconds
everyMinute()  : Cron
Set job schedule to every minute
everySecond()  : Cron
Set job schedule to every second
fridays()  : Cron
Set job schedule to Fridays
getDaysOfTheMonth()  : array<string|int, mixed>
Get days of the month
getDaysOfTheWeek()  : array<string|int, mixed>
Get days of the week
getGracePeriod()  : int
Get grace period
getHours()  : array<string|int, mixed>
Get hours
getMinutes()  : array<string|int, mixed>
Get minutes
getMonths()  : array<string|int, mixed>
Get months
getSchedule()  : string|null
Get schedule string
getSeconds()  : array<string|int, mixed>
Get seconds
hasGracePeriod()  : bool
Has grace period
hasSchedule()  : bool
Has schedule string
hasSeconds()  : bool
Has seconds
hourly()  : Cron
Set job schedule to hourly
hours()  : Cron
Set job schedule to by specific hours
minutes()  : Cron
Set job schedule to by specific minutes
mondays()  : Cron
Set job schedule to Mondays
monthly()  : Cron
Set job schedule to monthly
quarterly()  : Cron
Set job schedule to quarterly
render()  : string
Render the cron schedule string
saturdays()  : Cron
Set job schedule to Saturdays
schedule()  : Cron
Set cron schedule
seconds()  : Cron
Set job schedule to by specific seconds
setGracePeriod()  : Cron
Set grace period
sundays()  : Cron
Set job schedule to Sundays
thursdays()  : Cron
Set job schedule to Thursdays
tuesdays()  : Cron
Set job schedule to Tuesdays
updateSchedule()  : Cron
Update cron schedule
wednesdays()  : Cron
Set job schedule to Wednesdays
weekdays()  : Cron
Set job schedule to weekdays
weekends()  : Cron
Set job schedule to weekends
weekly()  : Cron
Set job schedule to weekly
yearly()  : Cron
Set job schedule to yearly
evaluateExpression()  : bool
Determine if the value satisfies the schedule expression
fieldPasses()  : bool
Determine whether one schedule field matches the corresponding value from the time being evaluated.

Properties

$daysOfTheMonth

Days of the month

protected array<string|int, mixed> $daysOfTheMonth = []

$daysOfTheWeek

Days of the week

protected array<string|int, mixed> $daysOfTheWeek = []

$gracePeriod

Grace period, in seconds, allowed between the scheduled time and the evaluation of it. Defaults to -1, i.e. the seconds value is disregarded and the schedule is due for the whole of its matching minute.

protected int $gracePeriod = -1

$hours

Hours

protected array<string|int, mixed> $hours = []

$minutes

Minutes

protected array<string|int, mixed> $minutes = []

$months

Months

protected array<string|int, mixed> $months = []

$schedule

Schedule string

protected string|null $schedule = null

$seconds

Seconds - Not a standard cron unit of time. The smallest time interval supported by cron is 1 minute.

protected array<string|int, mixed> $seconds = []

This is to support time intervals less than minute and down to 1 second.

Methods

__construct()

Constructor

public __construct([string|null $schedule = null ][, int $gracePeriod = -1 ]) : mixed

Instantiate the cron object

Parameters
$schedule : string|null = null
$gracePeriod : int = -1

__toString()

To string method

public __toString() : string
Return values
string

between()

Set job schedule to between two hours

public between(int $start, int $end) : Cron
Parameters
$start : int
$end : int
Return values
Cron

create()

Factory

public static create([string|null $schedule = null ]) : Cron
Parameters
$schedule : string|null = null
Return values
Cron

daily()

Set job schedule to daily (alias to hours)

public daily(mixed $hours[, mixed $minutes = null ]) : Cron
Parameters
$hours : mixed
$minutes : mixed = null
Return values
Cron

dailyAt()

Set job schedule to daily at specific time, i.e. 14:30

public dailyAt(string $time) : Cron
Parameters
$time : string
Return values
Cron

evaluate()

Evaluate the set cron schedule value against a time value

public evaluate([mixed $time = null ][, int|null $gracePeriod = null ]) : bool

The grace period governs how late an evaluation may be and still count as due. It applies only to minute-granularity schedules; a schedule with a seconds field is always evaluated exactly.

$gracePeriod = -1; disregards the seconds value - due for the whole of the matching minute (the default) $gracePeriod = 1-59; due within that many seconds of the scheduled time $gracePeriod = 0; strict evaluation to the 00 second

Note that a missed window is not made up later - there is no catch-up.

Parameters
$time : mixed = null
$gracePeriod : int|null = null
Tags
throws
Exception
Return values
bool

every10Minutes()

Set job schedule to every 10 minutes

public every10Minutes() : Cron
Return values
Cron

every10Seconds()

Set job schedule to every 10 seconds

public every10Seconds() : Cron
Return values
Cron

every15Minutes()

Set job schedule to every 15 minutes

public every15Minutes() : Cron
Return values
Cron

every15Seconds()

Set job schedule to every 15 seconds

public every15Seconds() : Cron
Return values
Cron

every20Minutes()

Set job schedule to every 20 minutes

public every20Minutes() : Cron
Return values
Cron

every20Seconds()

Set job schedule to every 20 seconds

public every20Seconds() : Cron
Return values
Cron

every30Minutes()

Set job schedule to every 30 minutes

public every30Minutes() : Cron
Return values
Cron

every30Seconds()

Set job schedule to every 30 seconds

public every30Seconds() : Cron
Return values
Cron

every5Minutes()

Set job schedule to every 5 minutes

public every5Minutes() : Cron
Return values
Cron

every5Seconds()

Set job schedule to every 5 seconds

public every5Seconds() : Cron
Return values
Cron

everyMinute()

Set job schedule to every minute

public everyMinute() : Cron
Return values
Cron

everySecond()

Set job schedule to every second

public everySecond() : Cron
Return values
Cron

fridays()

Set job schedule to Fridays

public fridays() : Cron
Return values
Cron

getDaysOfTheMonth()

Get days of the month

public getDaysOfTheMonth() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDaysOfTheWeek()

Get days of the week

public getDaysOfTheWeek() : array<string|int, mixed>
Return values
array<string|int, mixed>

getGracePeriod()

Get grace period

public getGracePeriod() : int
Return values
int

getHours()

Get hours

public getHours() : array<string|int, mixed>
Return values
array<string|int, mixed>

getMinutes()

Get minutes

public getMinutes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getMonths()

Get months

public getMonths() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSchedule()

Get schedule string

public getSchedule() : string|null
Return values
string|null

getSeconds()

Get seconds

public getSeconds() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasGracePeriod()

Has grace period

public hasGracePeriod() : bool

Only a grace period of exactly 0 - strict evaluation to the 00 second - grants no grace. A negative value is the loosest setting there is, not the absence of one.

Return values
bool

hasSchedule()

Has schedule string

public hasSchedule() : bool
Return values
bool

hasSeconds()

Has seconds

public hasSeconds() : bool
Return values
bool

hourly()

Set job schedule to hourly

public hourly([mixed $minutes = null ]) : Cron
Parameters
$minutes : mixed = null
Return values
Cron

hours()

Set job schedule to by specific hours

public hours(mixed $hours[, mixed $minutes = null ]) : Cron
Parameters
$hours : mixed
$minutes : mixed = null
Return values
Cron

minutes()

Set job schedule to by specific minutes

public minutes(mixed $minutes) : Cron
Parameters
$minutes : mixed
Return values
Cron

mondays()

Set job schedule to Mondays

public mondays() : Cron
Return values
Cron

monthly()

Set job schedule to monthly

public monthly(mixed $day[, mixed $hours = null ][, mixed $minutes = null ]) : Cron
Parameters
$day : mixed
$hours : mixed = null
$minutes : mixed = null
Return values
Cron

quarterly()

Set job schedule to quarterly

public quarterly([mixed $hours = null ][, mixed $minutes = null ]) : Cron
Parameters
$hours : mixed = null
$minutes : mixed = null
Return values
Cron

render()

Render the cron schedule string

public render() : string
Return values
string

saturdays()

Set job schedule to Saturdays

public saturdays() : Cron
Return values
Cron

schedule()

Set cron schedule

public schedule(string $schedule) : Cron

min hour dom month dow


  • OR non-standard -

sec min hour dom month dow


Parameters
$schedule : string
Return values
Cron

seconds()

Set job schedule to by specific seconds

public seconds(mixed $seconds) : Cron
Parameters
$seconds : mixed
Return values
Cron

setGracePeriod()

Set grace period

public setGracePeriod(int $gracePeriod) : Cron
Parameters
$gracePeriod : int
Return values
Cron

sundays()

Set job schedule to Sundays

public sundays() : Cron
Return values
Cron

thursdays()

Set job schedule to Thursdays

public thursdays() : Cron
Return values
Cron

tuesdays()

Set job schedule to Tuesdays

public tuesdays() : Cron
Return values
Cron

updateSchedule()

Update cron schedule

public updateSchedule() : Cron
Return values
Cron

wednesdays()

Set job schedule to Wednesdays

public wednesdays() : Cron
Return values
Cron

weekdays()

Set job schedule to weekdays

public weekdays() : Cron
Return values
Cron

weekends()

Set job schedule to weekends

public weekends() : Cron
Return values
Cron

weekly()

Set job schedule to weekly

public weekly(mixed $day[, mixed $hours = null ][, mixed $minutes = null ]) : Cron
Parameters
$day : mixed
$hours : mixed = null
$minutes : mixed = null
Return values
Cron

yearly()

Set job schedule to yearly

public yearly([bool $endOfYear = false ][, mixed $hours = null ][, mixed $minutes = null ]) : Cron
Parameters
$endOfYear : bool = false
$hours : mixed = null
$minutes : mixed = null
Return values
Cron

evaluateExpression()

Determine if the value satisfies the schedule expression

protected evaluateExpression(string $expression, mixed $value) : bool
Parameters
$expression : string
$value : mixed
Return values
bool

fieldPasses()

Determine whether one schedule field matches the corresponding value from the time being evaluated.

protected fieldPasses(array<string|int, mixed> $field, int $value) : bool

This is the per-field test that evaluate() used to inline six times over. The three cases, in the order the original checked them: the wildcard '*', a literal value present in the field, and - only for a single-element string field - a compound expression (a comma list, a step, or a range) handed off to evaluateExpression().

The loose in_array() comparison is intentional and load-bearing: field values arrive as strings when parsed out of a schedule string but as ints when set through the fluent helpers (hourly(), daily(), and friends all assign ints), so both have to compare equal to the int taken from the timestamp.

Parameters
$field : array<string|int, mixed>
$value : int
Return values
bool

        
On this page

Search results