Download the PHP package jerome/matrix without Composer
On this page you can find all versions of the php package jerome/matrix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jerome/matrix
More information about jerome/matrix
Files in jerome/matrix
Package matrix
Short Description Event-driven asynchronous helpers and concurrency control for ReactPHP.
License MIT
Homepage https://thavarshan.com
Informations about the package matrix
Matrix
Matrix provides small, event-driven async helpers for ReactPHP. It makes promise composition, concurrency limits, retries, timeouts, cancellation, and rate limiting consistent without pretending to create threads or process-level parallelism.
Requirements
- PHP 8.3 or newer
react/event-loop1.6 or newerreact/promise3.3 or newer
No pcntl, posix, or sockets extension is required.
Install it with Composer:
Core usage
Import the helpers explicitly in each file:
async() schedules a callable on the ReactPHP loop. The callable must use non-blocking I/O; sleep(), file_get_contents(), CPU-heavy work, and synchronous database clients still block the loop.
await() is a top-level synchronous bridge for CLI scripts and other code that owns the loop. It must not be called from inside an already-running loop callback. Use promise chaining inside an event-driven application instead.
Composition and concurrency
All combinators accept promises or plain values. all(), race(), and any() accept any iterable. all() preserves keys:
map() accepts arrays or generators, preserves keys, and limits active work when $concurrency is greater than zero. pool() does the same for zero-argument task callables. Both stop scheduling new work after the first failure and observe already-running tasks.
batch() groups values in encounter order and flattens each batch result into a list. waterfall() passes each result to the next callable.
Timeouts, retries, and cancellation
Timeouts cancel the losing operation and their timer. Retry backoff is event-loop based. Invalid durations, limits, or attempt counts throw InvalidArgumentException before work is scheduled.
cancellable() returns a native ReactPHP PromiseInterface. Calling cancel() invokes the cleanup callback once and forwards cancellation to the wrapped promise:
Rate limiting
The limiter uses a sliding window and removes cancelled queued calls before execution.
Events and metrics
Matrix emits promise.created, promise.resolved, promise.rejected, and promise.timeout events for Matrix-created operations. Listener exceptions are isolated so an observer cannot break application work.
metricsCollector()->getMetrics() keeps cumulative counters and bounded timing samples. Percentiles describe the most recent 1,024 samples per operation series, so metrics remain safe in long-running workers.
Development
The check runs Composer validation, Pint, PHPStan at maximum level, and PHPUnit. See UPGRADING.md for the 3.x to 4.0 migration notes.
License
Matrix is released under the MIT license.