API Network FiberConcurrentExecutor - evansims/openfga-php GitHub Wiki
Fiber-based concurrent executor implementation. This implementation uses PHP 8.1+ Fibers to execute tasks concurrently without the overhead of threads or processes. Fibers provide cooperative multitasking, allowing efficient concurrent execution of I/O-bound tasks such as HTTP requests.
Table of Contents
OpenFGA\Network
public function executeParallel(array $tasks, int $maxConcurrent = 10, bool $stopOnFirstError = false): arrayExecute multiple tasks in parallel. Executes the provided tasks concurrently up to the specified concurrency limit. Tasks are executed as they become available and results are collected in the same order as the input tasks.
| Name | Type | Description |
|---|---|---|
$tasks |
array |
|
$maxConcurrent |
int |
Maximum number of concurrent executions |
$stopOnFirstError |
bool |
Stop all tasks when first error is encountered |
array — Array of results or exceptions in the same order as tasks
public function getMaxRecommendedConcurrency(): intGet the maximum recommended concurrency for the current environment. This provides a hint about the optimal concurrency level based on system resources and implementation constraints.
int — Maximum recommended concurrent tasks
public function supportsConcurrency(): boolCheck if the executor supports concurrent execution. Some environments may not support true concurrency (for example missing Fiber support in PHP < 8.1). This method allows checking if the executor can actually run tasks concurrently or will fall back to sequential execution.
bool — True if concurrent execution is supported