Skip to content

Background cron tasks

Greg Bowler edited this page May 17, 2026 · 3 revisions

Some WebEngine projects need work to happen outside the normal request cycle. That is where background cron tasks fit in.

What cron tasks are for

Typical cron jobs include:

  • refreshing cached remote data
  • sending queued emails or notifications
  • importing data from third-party services
  • cleaning up expired temporary files

These tasks should not wait for a browser request. They are better run on a schedule.

The crontab file

To define scheduled tasks for a project, add a crontab file in the project root.

That file contains schedule expressions and the commands to run when each schedule becomes due. WebEngine can then watch that file during development and execute the due commands locally.

Keep the commands project-relative and focused on application work. For example, a cron task might run a PHP script from cron/, refresh generated files in cache/, or call a CLI entry point inside your application.

Local development

During local development, gt run can keep the cron watcher running alongside the web server and asset build watcher. That makes scheduled tasks part of the same development loop as page requests.

If you want to work with the scheduled tasks on their own, use gt cron.

See [[gt commands#gt cron]] for the available flags such as watch mode, validation, and explanation output.

Production use

In production, the exact scheduling mechanism depends on your hosting environment. The important requirement is that the same commands your project expects are run on the intended schedule.

Treat scheduled jobs like any other application code: keep them version-controlled, predictable, and easy to test manually.


Move back to Run an application, or continue to the request-response lifecycle.

Clone this wiki locally