Skip to main content
Build an app that runs recurring maintenance jobs on fixed cadences. You put #[Scheduled] on zero-argument methods of a #[Service] bean and enable scheduling on the application class. The framework runs each tick in a dedicated worker process, so a slow job never blocks web requests. Use scheduled tasks for work that runs on a fixed cadence — cleanup, reports, cache warming. Use a daemon thread instead when the work must run continuously.
Scheduling fires once per process. Run exactly one instance of this app — a second instance would run every tick twice.
If you must scale this app to multiple instances, guard each tick with a distributed lock so only one instance runs it. See Locking for the #[Lockable] annotation and supported lock managers.

Prerequisites

You need PHP 8.5 or later with the swoole and pcntl extensions. No external services are needed.

Project structure

The sample uses this layout:

Install dependencies

Require the framework package:

Source files

Switch between the source files. Each tab shows the exact file from the sample.
The single entry point. #[EnableScheduling] activates the #[Scheduled] ticks in the scanned namespace.

Configuration

No module is needed — scheduling is a core framework feature. The full sample application.yml sets the server, app identity, and the scheduling worker pool:
See Configuration for every application.yml key.

Run the app

Start the app and trigger the jobs with short delays to verify them quickly. 1. Start the application:
2. Seed a stale temp file and watch the hourly tick:
About a minute after boot (initialDelay: 60), the app log shows the cleanup result:
3. Check the daily summary log:
About two minutes after boot (initialDelay: 120), the summary line appears:
The short initial delays let you verify both ticks without waiting an hour or a day — the steady-state cadence stays hourly and daily via fixedDelay.

Next steps

  • Read Scheduling for fixedRate, placeholder-driven intervals, and pool tuning.
  • Read the Daemon example when your work must run continuously instead of on a cadence.