Documentation Packages Getting Started FAQ Support

Asynchronous concurrency made simple

Amp is a non-blocking 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 {
    $gh = "";
    $response = yield  $http->request($gh);
} 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


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 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


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


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

Use Cases

Amp can be used wherever you have to wait for multiple I/O activities to happen without them having to happen in a specific order (sequentially). It can be used in all SAPIs reaching from Apache and PHP-FPM to PHP-CLI. If you don't have a long running application, you might find Amp\Promise\wait() helpful.

Multiplexing I/O

The key benefit of non-blocking I/O is that it can be multiplexed. Multiple I/O requests can happen concurrently. The event loop simply waits for any I/O event to occurr instead of waiting for a single I/O operations. This enables parallel HTTP requests, SQL queries or any other I/O related activity.

Reacting to I/O

Maybe you're not interested in speeding up your application by using concurrent I/O (we bet you are), but want to write a daemon that only wakes up the CPU if some I/O event occurred so you can react to that event? Amp's event loop provides exactly that. It lets you register callbacks to react to I/O events.

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?