Cron
Five- or six-field cron expressions and event-loop scheduling.
Installation
Section titled “Installation”composer config repositories.localzet-cron vcs https://github.com/localzet/Croncomposer require localzet/cron:dev-mainScheduling on the event loop
Section titled “Scheduling on the event loop”new localzet\Cron($rule, $callback, $name = '') registers a Timer-driven job. A running Server 4.x loop is required; this is neither system crontab nor a standalone daemon. Rules have five fields (minute through weekday), or six with seconds first. Validate syntax using CronParser::isValid().
CronParser::parse($rule, $startTime) returns matches within the evaluated minute, not the next occurrence over an arbitrary future interval. The implementation adds second offsets to startTime: pass a minute boundary when calling it directly. PHP date/time settings determine the timezone.
getRule/getCallback/getName/getId inspect a registration; getAll() returns jobs; destroy() or Cron::remove($id) removes one. This does not automatically cancel one-shot Timer callbacks already scheduled. Multiple workers create independent schedules: use one scheduler process or an external lock for singleton work. Long synchronous callbacks block the process.
Requirements
Section titled “Requirements”- php: ^8.1
- localzet/server: ^4.5
Example
Section titled “Example”<?php
declare(strict_types=1);
use localzet\CronParser;
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('UTC');$parser = new CronParser();$minute = strtotime('2026-10-17 12:00:00 UTC');$times = $parser->parse('*/15 * * * * *', $minute);
echo json_encode(array_map(static fn (int $time): string => gmdate('H:i:s', $time), $times), JSON_THROW_ON_ERROR), PHP_EOL;Source · AGPL-3.0