Skip to content
Greg Bowler edited this page May 6, 2026 · 3 revisions

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's cron/ 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.

What this library covers

  • Parsing standard five-field crontab expressions.
  • Ignoring comments and blank lines in crontab files.
  • 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 ExpressionFactory implementations.

A small example

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 --now

If 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.

Clone this wiki locally