#[DaemonThread] annotation on a ServerWorkerProcess subclass. The framework starts the daemon with your app and restarts it if it crashes, so you never wire up your own process supervisor.
Use a daemon for work that must always be running — watching a directory, polling a queue, or tailing a stream. Use scheduled tasks instead when the work runs on a fixed cadence.
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.- DaemonSampleApplication.php
- InboxWatcherDaemon.php
- bin/application.php
- composer.json
The single entry point. It points Winter Boot at the
config directory and at the sample namespace.Configuration
No module is needed — the daemon is a core framework feature. The full sampleapplication.yml sets only the server and app identity:
application.yml key.
Run the app
Start the app, drop a file into the inbox, and watch the daemon process it. 1. Start the application:/tmp/inbox and /tmp/processed on startup and begins scanning.
2. Drop a file into the inbox:
report.txt in the processed directory within 5 seconds, and the app log shows the line count:
Next steps
- Read Daemon Threads for process types,
coreSizescaling, and supervision details. - Read the Scheduler example when your work runs on a fixed cadence instead of continuously.