beauty-framework / parallels
Beauty Parallels (RoadRunner, Fibers)
1.0.0
2025-06-10 10:01 UTC
Requires
- php: >=8.1
- opis/closure: ^4.3
- spiral/roadrunner-jobs: ^4.6
This package is not auto-updated.
Last update: 2025-06-11 08:11:44 UTC
README
A lightweight concurrency manager for PHP, supporting Fiber-based parallel execution out of the box. Optionally, you can use RoadRunner jobs-based parallelism (WIP).
Installation
composer require beauty-framework/parallels
Quick Start
use Beauty\Parallels\Concurrent; use Beauty\Parallels\WorkersName; $results = Concurrent::run([ 'task-1' => fn() => 1 + 1, 'task-2' => fn() => strtoupper('hello'), ]); print_r($results);
Output:
[ 'task-1' => 2, 'task-2' => 'HELLO', ]
Execution Modes
Concurrent::run(array $callbacks, int $timeoutSeconds = 10, string $type = WorkersName::FIBER): array
Available modes:
Mode | Description |
---|---|
fiber |
Default. Uses PHP Fibers (cooperative multitasking) |
process |
WIP. Spawns tasks via RoadRunner Jobs pipeline |
You can explicitly choose the execution strategy:
Concurrent::run([ 'a' => fn() => 42, ], 5, WorkersName::FIBER);
Notes
- Fiber-based mode is enabled by default, lightweight and fast.
- RoadRunner-based process execution is under active development and is experimental.
TODO
- Finish implementation of
ProcessConcurrencyWorker
based onspiral/roadrunner-jobs
- Add serialization-safe closures via
opis/closure
- Result collector with Redis or temp files
- Per-task exception handling and cancellation support
- Tests
License
MIT