Context
The current ForkManagerInterface::fork(callable $workerCallback, int $workerCount = 1) (and implementation) only accepts a single callback and spawns N workers for that same callback.
This is limiting:
- we can only scale the same unit of work;
- there is no way to define different routines per worker in the same call.
Why this matters
In practice, if a caller needs worker types like:
- one process validating input,
- one process doing IO-bound work,
- one process handling notifications,
it currently requires multiple fork() calls and orchestration outside the component, or custom dispatch logic.
Proposed change
Add support for multi-callback worker pools so one fork orchestration can map each callback independently.
Recommended API (non-breaking first)
Keep existing behavior and add:
forkMany(array $workerCallbacks) to dispatch a heterogeneous callback set.
Proposed behavior:
- key/index in the array identifies each worker callback task;
- each callback receives the same shared context as today (or explicit context strategy if needed);
- result/exception collection remains deterministic per worker.
Alternative (possibly breaking)
Replace fork(callable $workerCallback, int $workerCount = 1) with a variadic/callback-list signature.
Because this is BC-sensitive, this should be considered carefully.
Non-goals
- changing the fork strategy/scheduler itself;
- adding process-pool abstractions or advanced load-balancing in this first iteration.
Acceptance criteria
- New tests covering:
- mixed callbacks executed in the same fork invocation;
- worker count aligned with callback list length;
- independent callback failure reporting.
- Keep old
fork(callable, int) behavior untouched when using the legacy API.
Context
The current
ForkManagerInterface::fork(callable $workerCallback, int $workerCount = 1)(and implementation) only accepts a single callback and spawns N workers for that same callback.This is limiting:
Why this matters
In practice, if a caller needs worker types like:
it currently requires multiple
fork()calls and orchestration outside the component, or custom dispatch logic.Proposed change
Add support for multi-callback worker pools so one fork orchestration can map each callback independently.
Recommended API (non-breaking first)
Keep existing behavior and add:
forkMany(array $workerCallbacks)to dispatch a heterogeneous callback set.Proposed behavior:
Alternative (possibly breaking)
Replace
fork(callable $workerCallback, int $workerCount = 1)with a variadic/callback-list signature.Because this is BC-sensitive, this should be considered carefully.
Non-goals
Acceptance criteria
fork(callable, int)behavior untouched when using the legacy API.