From 77fec2b4a72db1f75ecebeffdbbc987ab77c8db8 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Tue, 7 Oct 2025 21:23:40 +0200 Subject: [PATCH] Adds docs. --- docs/worker.md | 46 ++++++++++++++++++++++++++++++++++ testdata/tasks/task-worker.php | 8 +++--- threadtaskworker.go | 3 ++- 3 files changed, 52 insertions(+), 5 deletions(-) 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 +