#[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.
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 theswoole 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.- SchedulerSampleApplication.php
- schedule/MaintenanceScheduler.php
- bin/application.php
- composer.json
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 sampleapplication.yml sets the server, app identity, and the scheduling worker pool:
application.yml key.
Run the app
Start the app and trigger the jobs with short delays to verify them quickly. 1. Start the application:initialDelay: 60), the app log shows the cleanup result:
initialDelay: 120), the summary line appears:
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.