amphp/amp
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
revolt/event-loop | v1.0.6 | 35.61 kB | MIT | prod |
"amphp/amp" is a non-blocking concurrency framework designed to enable asynchronous programming in PHP applications. It uses the fundamental primitives of futures and cancellations along with modern fiber concepts shipped with PHP 8.1. The package alleviates the need for generator-based coroutines or callbacks used in traditional synchronous PHP models; instead, it provides an efficient way to utilize time usually spent waiting for I/O operations by performing concurrent tasks. With the use of the Amp\async()
function, "amphp/amp" runs things concurrently, making it a valuable package for developers seeking to improve the performance and responsiveness of their PHP applications.
To use "amphp/amp", you start by installing it via Composer with the command: composer require amphp/amp
. This makes the "amphp/amp" API readily available in your PHP application. Using "amphp/amp" is as simple as making use of its Amp\async()
function to run tasks concurrently. There’s no necessity for generator-based coroutines or callbacks as you write code almost like synchronous or blocking code. For example:
<?php
use function Amp\delay;
require __DIR__ . '/vendor/autoload.php';
Amp\async(function () {
print '++ Executing callback passed to async()' . PHP_EOL;
delay(3);
print '++ Finished callback passed to async()' . PHP_EOL;
});
print '++ Suspending to event loop...' . PHP_EOL;
delay(5);
print '++ Script end' . PHP_EOL;
The package also provides other functionalities like awaiting HTTP responses concurrently using Future\await()
, creating DeferredFuture
, and allowing manual operation cancellations using DeferredCancellation::cancel()
. Futures can be created by calling Amp\async()
which runs a function as a coroutine in a different Fiber.
The documentation for "amphp/amp" is hosted within the README file on its GitHub page at https://github.com/amphp/amp. It provides a comprehensive guide covering the motivation behind the package, installation, functionalities, usage examples, as well as information on versioning, security, and license. For further references to understand the underlying concepts, you can explore its links to other resources like "Revolt", "Fibers", and the "Hello World example" provided within the guide.