Skip to main content
Build an app with a supervised background daemon that watches an inbox directory and processes new files as they arrive. You use the #[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 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. 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 sample application.yml sets only the server and app identity:
See Configuration for every 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:
The daemon creates /tmp/inbox and /tmp/processed on startup and begins scanning. 2. Drop a file into the inbox:
3. Verify processing:
You see 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, coreSize scaling, and supervision details.
  • Read the Scheduler example when your work runs on a fixed cadence instead of continuously.