Prerequisites
Async support is powered by the Swoole PHP extension. Install it via PECL and enable it in yourphp.ini before proceeding.
1
Install the Swoole extension
2
Enable Swoole in php.ini
Enable Async on Your Application Class
Add the#[EnableAsync] attribute to your #[WinterBootApplication] class. The framework validates at boot time that both attributes are present and that Swoole is loaded — a TypeError or AnnotationException is thrown otherwise.
MyApplication.php
Mark a Method as Async
Annotate anypublic, non-final, non-abstract method on a #[Service] or #[Component] bean with #[Async]. When the method is called at runtime the framework serialises its arguments and dispatches the call to a background worker — the caller receives control back instantly.
NotificationService.php
Return Values
An#[Async] method must declare a void return type. Because the caller does not wait for the worker to finish, there is no mechanism to return a value back to the calling code.
Method Parameter Constraints
The framework serialises method arguments to pass them to a worker process. Each parameter must be typed as a scalar (int, float, string, or bool). Avoid mixed types; the framework logs an error at boot if it encounters them.
ReportService.php
Configuration
Configure the async worker pool inapplication.yml under winter.task.async:
application.yml
int
Total number of dedicated background worker processes to start.
int
Maximum number of async calls that can be queued and awaiting execution at any one time.
int
Upper limit in bytes for the combined serialised arguments of a single async call.
Queue Storage
By default, Winter Boot uses shared memory as its async queue. Pending calls are lost if the application restarts. For persistence across restarts, switch to the Redis-backed queue store provided by thewinter-data-redis module:
application.yml
The Redis queue store requires the
winter-data-redis module and a configured Redis connection. With it enabled, queued calls survive application restarts.