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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package matrix

Matrix

Latest Version on Packagist Tests Lint CodeQL PHPStan PHP Version License Total Downloads GitHub Stars

Matrix is a PHP library that brings event-driven, asynchronous programming to PHP, inspired by JavaScript's async/await syntax. Built on top of ReactPHP's event loop, Matrix makes it easier to write non-blocking I/O operations and manage concurrency with a simple, intuitive API.

Understanding Async in PHP

Important: PHP runs in a single-threaded environment. Matrix doesn't create true parallelism but enables event-driven, non-blocking I/O operations through ReactPHP's event loop. This means:

Matrix shines when dealing with I/O-heavy applications like API clients, web scrapers, or microservices.

Why Choose Matrix?

Matrix simplifies ReactPHP development by providing a familiar async/await syntax while maintaining full compatibility with ReactPHP's ecosystem. It handles the complexity of promise management and event loop integration behind a clean, intuitive API.

Key Features

Installation

Install Matrix via Composer:

Requirements

ReactPHP promises and the event loop will be installed automatically via Composer.

API Overview

Core Functions

async(callable $callable): PromiseInterface

Wraps a callable into an asynchronous function that returns a promise.

await(PromiseInterface $promise, ?float $timeout = null): mixed

Awaits the resolution of a promise and returns its value. Optionally accepts a timeout in seconds.

Promise Combination

all(array $promises): PromiseInterface

Runs multiple promises concurrently and returns a promise that resolves with an array of all results.

race(array $promises): PromiseInterface

Returns a promise that resolves with the value of the first resolved promise in the array.

any(array $promises): PromiseInterface

Returns a promise that resolves when any promise resolves, or rejects when all promises reject.

Concurrency Control

map(array $items, callable $callback, int $concurrency = 0, ?callable $onProgress = null): PromiseInterface

Maps an array of items through an async function with optional concurrency control and progress tracking.

batch(array $items, callable $batchCallback, int $batchSize = 10, int $concurrency = 1): PromiseInterface

Processes items in batches rather than one at a time for improved performance.

pool(array $callables, int $concurrency = 5, ?callable $onProgress = null): PromiseInterface

Executes an array of callables with limited concurrency.

Error Handling and Control

timeout(PromiseInterface $promise, float $seconds, string $message = 'Operation timed out'): PromiseInterface

Creates a promise that times out after a specified period.

retry(callable $factory, int $maxAttempts = 3, ?callable $backoffStrategy = null): PromiseInterface

Retries a promise-returning function multiple times until success or max attempts reached.

cancellable(PromiseInterface $promise, callable $onCancel): CancellablePromise

Creates a cancellable promise with a cleanup function.

withErrorContext(PromiseInterface $promise, string $context): PromiseInterface

Enhances a promise with additional error context.

Timing and Flow Control

delay(float $seconds, mixed $value = null): PromiseInterface

Creates a promise that resolves after a specified delay.

waterfall(array $callables, mixed $initialValue = null): PromiseInterface

Executes promises in sequence, passing the result of each to the next.

rateLimit(callable $fn, int $maxCalls, float $period): callable

Creates a rate-limited version of an async function.

Examples

Running Asynchronous Tasks

Using the Await Syntax

Handling Errors

Chaining Promises

Non-blocking HTTP Requests Example

Database Operations Example (using ReactPHP MySQL)

API Integration Example with Retry

Advanced Testing

Matrix includes a comprehensive test suite to ensure reliability, including:

Unit Tests

Test individual components in isolation:

Integration Tests

Test how components work together in real-world scenarios:

Error Handling Tests

Test that errors are properly handled and propagated:

Concurrency Pattern Tests

Test various concurrency patterns:

Performance Considerations

Common Pitfalls to Avoid

❌ Using Blocking Operations

✅ Use Non-blocking Alternatives

❌ CPU-Intensive Operations

✅ Break Up Heavy Operations

How It Works

Matrix provides an intuitive async/await interface on top of ReactPHP's powerful event loop system:

  1. Event Loop Management: The async() function schedules work on ReactPHP's event loop, enabling non-blocking execution of I/O operations
  2. Promise Interface: All async operations return ReactPHP promises with then() and catch() methods for handling success and error cases
  3. Synchronous Await: The await() function runs the event loop until the promise resolves, providing a synchronous-looking interface
  4. Concurrency Control: Functions like map(), batch(), and pool() limit concurrent operations to prevent resource exhaustion
  5. Error Handling: Custom exception classes provide detailed information about failures, timeouts, and retry attempts

Key Point: Matrix doesn't change PHP's single-threaded nature but makes it much easier to write efficient, non-blocking I/O code that can handle thousands of concurrent operations.

Testing

Run the test suite to ensure everything is working as expected:

Contributing

We welcome contributions! To get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure your code follows the project's coding standards and includes appropriate tests.

License

Matrix is open-source software licensed under the MIT License.


All versions of matrix with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-pcntl Version *
ext-posix Version *
react/event-loop Version ^1.5
react/promise Version ^3.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jerome/matrix contains the following files

Loading the files please wait ....