Asynchronous concurrency made simple

Amp is a concurrency framework for PHP providing primitives to manage concurrency such as an event loop, promises, and asynchronous iterators.

It implements coroutines using PHP's generators to avoid callback or then() hells. Promise consumption works without callbacks and allows ordinary catch clauses just as synchronous code for handling errors.

try {
    $url = "https://github.com/";
    $response = yield  $httpClient->request($url);
} catch (HttpException $e)  {
    // handle error
}

Basic Building Blocks

Event Loop

The event loop is the main task scheduler of every asynchronous application. It dispatches associ­ated handlers once the registered events happen. Read more about the event loop

Promises

A promise is a placeholder for the result of an asynchronous operation. While synchronous programs block until a result is available, asynchronous programs return a placeholder which gets filled in with the result at a later time. Read more about promises

Coroutines

Coroutines are interruptible functions that can be paused and resumed. Amp uses Generators to allow promise consumption without callbacks. Read more about coroutines

Advanced Building Blocks

Iterators

Asynchronous iterators allow the consumption of collections of values, one at a time. Instead of resolving a promise once all results are available, iterators make it possible to consume items of a collection as soon as they become available. Read more about iterators

Streams

Amp provides a stream abstraction that makes working with non-blocking I/O way easier. Don't worry about read- and write-watchers, buffering, and backpressure. Read more about streams


Compatible Packages

Amphp offers a number of high-quality packages ranging from basic network components to more advanced components like our Aerys HTTP server. All compatible packages should use the amphp tag on GitHub. Many packages are listed on our dedicated Packages page.

An adapter is also provided to allow Amp to operate ReactPHP components.


Sounds Interesting?