diff --git a/docs/worker.md b/docs/worker.md index 81c18266..64aed5c1 100644 --- a/docs/worker.md +++ b/docs/worker.md @@ -179,3 +179,49 @@ $handler = static function () use ($workerServer) { // ... ``` + +## Task workers + +`workers` are used to handle HTTP requests, but FrankenPHP also supports `task workers` that can handle +asynchronous tasks in the background. Task workers can also be used to just execute a script in a loop. + +```caddyfile +frankenphp { + task_worker { + name my-task-worker # name of the task worker + file /path/to/task-worker.php # path to the script to run + num 4 # number of task workers to start + args arg1 arg2 # args to pass to the script (to simulate $argv in cli mode) + } +} +``` + +Tasks workers may call `frankenphp_handle_task()` to wait for a task to be assigned to them. Tasks +may be dispatched from anywhere in the process using `frankenphp_dispatch_task()`. + +```php +