-
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
phpgt/cron lets us schedule PHP application tasks using familiar crontab syntax, then run the due jobs from PHP itself.
That means we can keep scheduled work close to the project instead of scattering it across system crontab entries, custom shell scripts, and framework-specific glue. A job can be:
- a shell command
- a static PHP function call
- a
go()function inside a file in the project'scron/directory
Note
In WebEngine development, this library is already included. WebEngine's gt run command starts the cron runner alongside the local web server and build watcher, and gt cron can be used when we only want the scheduler.
- Parsing standard five-field crontab expressions.
- Ignoring comments and blank lines in
crontabfiles. - Running due jobs once or continuing to watch for future jobs.
- Calling static PHP methods directly from the crontab.
- Resolving short script names from the local
cron/directory. - Running
go()cron scripts with query-string input and optional dependency injection. - Extending the schedule language through custom
ExpressionFactoryimplementations.
crontab:
# Run a direct shell command every hour.
0 * * * * printf 'Hourly report built\n'
# Run a short script alias from cron/hello.php every minute.
* * * * * hello
# Run a static method every weekday evening.
0 18 * * MON-FRI App\Task\Digest::send("team@example.com")
Run the scheduler from the project root:
vendor/bin/cron --nowIf the jobs above are due, the runner executes them immediately. To keep the process alive and wait for future jobs, use --watch.
Start with Quick start guide to build a working project from scratch.
PHP.GT/Cron is a separately maintained component of PHP.GT/WebEngine.