amphp/amp: fibers, futures, and the event loop it no longer ships
A non-blocking concurrency framework for PHP applications. 🐘
At a glance
- What is it?
- amphp/amp turned PHP 8.1 fibers into a concurrency primitive and then handed its event loop to Revolt. Here is what the split changed, how the pieces fit, and where the cooperative scheduling model bites.
- Who is it for?
- Adopt amphp/amp if you already run PHP 8.1 or newer, want non-blocking HTTP, socket or database access without callback style code, and can accept that one blocking call freezes every coroutine in the process. Do not adopt it to use multiple CPU cores, which is amphp/parallel's job, or expecting it to ship its own event loop, since it now uses Revolt instead.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- amphp/amp4,429 ★ · -3
| Repository | 2026-09-23 | 2026-11-15 |
|---|---|---|
| amphp/amp | 4.4k | 4.4k |
-3 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The split that left amphp/amp without an event loop
amphp/amp is not an event loop. That is the first thing to understand, and it is easy to miss because the package still carries the name of the framework that once contained one. The project now uses Revolt instead of shipping an event loop implementation with amphp/amp. Revolt is a separate package that you require yourself, and even when it arrives automatically as a transitive dependency the README tells you to require it explicitly.
What remains in amphp/amp is narrow and specific: futures and cancellations as fundamental primitives for asynchronous programming. The package description calls it a collection of event-driven libraries for PHP designed with fibers and concurrency in mind, but amphp/amp specifically is the primitives layer. The wider ecosystem lives in sibling packages: byte-stream for a stream abstraction, socket for UDP and TCP including TLS, http-client for HTTP/1.1 and HTTP/2, http-server for an application server, mysql and postgres for non-blocking database access, and parallel for multi-core work.
The last push to the default branch was 26 July 2026, the same day the v3.1.3 tag was published. The repository is licensed MIT.
Why cooperative scheduling exists at all in PHP
The motivation section is worth reading closely because it argues from a specific pain rather than from performance numbers. PHP executes one line after another in sequential order, yet a program usually consists of several independent sub-programs that could run at once. Query a database and the process sends the query and waits for the response in a blocking manner; once the response arrives, the next thing starts. The argument for concurrency is to stop sitting idle during that wait: send the next query, or make an HTTP call to an API, and use the time that would otherwise be lost to I/O.
Earlier PHP approaches used callbacks and generators, shipped in PHP 5. Both suffered from the what color is your function problem, which amphp/amp credits to a 2015 article by that name. Fibers, shipped in PHP 8.1, removed the need to label functions, so generator based coroutines and Amp\call() boilerplate are gone in the current line.
The comparison the README makes is precise: like several programs sharing one CPU core, each getting a timeslot. Coroutines are not preemptive, though. They have no fixed timeslot and must voluntarily give control back to the event loop. Only one coroutine runs at any given moment and the rest are suspended. That single fact is the source of both the ergonomics and the failure mode.
Future has no then, and that is deliberate
A Future is an object representing the eventual result of an asynchronous operation. Other languages call this a promise, and amphp/amp names it differently for a stated reason: a Future does not have a then method, which is typical of most promise implementations. That single omission changes how code reads. Instead of chaining callbacks, you await the result inside a coroutine, at the point where you actually need the value.
A future may be in one of three states: Completed, meaning it finished successfully; Errored, meaning it failed with an exception; or Pending. Futures are primarily designed to be awaited in coroutines, though Future also has methods which act upon the result and return another future, so the callback style is available without being the default shape.
Cancellation is the other fundamental primitive in the package. The examples directory contains examples/async.php and examples/cancellation.php, which is a reasonable signal that cancelling in-flight work is a designed-for case rather than an afterthought. Combined with Amp\async() to start a coroutine and Future::await() to collect the result, the two primitives cover the majority of what a caller needs without writing a single generator.
Two composer commands, and why you run the second one yourself
Installation is a Composer dependency. The core package is one command:
composer require amphp/ampThe second command matters more than it looks. The README says that if you use this library it is very likely you want to schedule events using Revolt, which you should require separately, even if it is automatically installed as a dependency. In other words the dependency graph will satisfy itself and you can still end up with an undeclared direct dependency on the package that actually drives your program:
composer require revolt/event-loopThat advice is not ceremony. Low-level suspension and resumption of coroutines is handled by Revolt's Suspension API, and callbacks registered on the Revolt event loop are automatically run as coroutines, so suspending inside them is safe. If you omit the explicit require, your code still works until a future refactor needs you to reason about which package owns the loop.
Two ways to start work: the Suspension and Amp\async()
The suspension example is the bare mechanism. You fetch a Suspension from the event loop, arrange a delayed callback that resumes it, then suspend. Because the callback resumes the suspension with null, the calling fiber continues at the same point:
<?php
use Revolt\EventLoop;
require __DIR__ . '/vendor/autoload.php';
$suspension = EventLoop::getSuspension();
EventLoop::delay(5, function () use ($suspension): void {
print '++ Executing callback created by EventLoop::delay()' . PHP_EOL;
$suspension->resume(null);
});
print '++ Suspending to event loop...' . PHP_EOL;
$suspension->suspend();
print '++ Script end' . PHP_EOL;Amp\async() is the higher level entry point, wrapping a callable in a new fiber with an independent call stack. This version prints the suspending line, delays for five seconds, and prints the script end, with the async callback interleaving into that window:
<?php
require __DIR__ . '/vendor/autoload.php';
Amp\async(function () {
print '++ Executing callback passed to async()' . PHP_EOL;
Amp\delay(3);
print '++ Finished callback passed to async()' . PHP_EOL;
});
print '++ Suspending to event loop...' . PHP_EOL;
Amp\delay(5);
print '++ Script end' . PHP_EOL;Between them these two snippets show the whole model: one fiber running, control handed to the loop, the loop resuming work when a timer expires, a stream operation becomes possible, or an awaited Future completes.
Any blocking call freezes every coroutine, not just its own
Here is the sharp edge. The README states it without hedging: any blocking I/O function blocks the entire process while waiting for I/O, and you will want to avoid them. Because fibers are cooperatively scheduled and not preemptive, a fiber cannot be yanked out of a blocking system call. One synchronous file read inside one coroutine and every other coroutine in that process waits with it, which defeats the whole premise of using futures.
This is not a theoretical warning attached to a list of banned functions. The libraries provided by AMPHP avoid blocking for I/O, including amphp/mysql and amphp/postgres for non-blocking database access. The Hello World example linked from the installation guide exists specifically to demonstrate the effect of blocking functions.
A second practical limit is platform configuration. Extensions are not required for the package itself, but the Revolt extensions note says they are needed if your app requires a high number of concurrent socket connections, with the limit usually configured at 1024 file descriptors. A fiber-based design makes opening many concurrent connections easy, so you can reach a file descriptor ceiling that a sequential design would never have approached.
Where amphp/parallel and ReactPHP diverge from this core
Two comparisons are worth being concrete about. The first is inside the same family: amphp/parallel provides parallel processing to utilize multiple CPU cores and offload blocking operations. amphp/amp gives you one event loop running one coroutine at a time. If your workload is CPU bound, or if you need to keep a known-blocking call but still make progress, amphp/parallel is the sibling package that addresses it, and pairing them is the intended path rather than a workaround.
The second is about where the event loop lives. On amphp/amp the loop lives in Revolt, a distinct project with its own site at revolt.run, and the amphp/amp README links it as the thing now used instead of a shipped implementation. Code that assumes the loop arrives with the concurrency package has to change when it moves.
There is also a version boundary to respect. The default branch is 3.x and the recent releases include v3.1.3 and v3.1.2 from 2026, alongside v2.6.5 from 3 September 2025. The generator based coroutine approach belongs to earlier versions, and code written against Amp\call() or generator returns is not code for this branch.
Editorial conclusion
Adopt amphp/amp if you already run PHP 8.1 or newer, want non-blocking HTTP, socket or database access without callback style code, and can accept that one blocking call freezes every coroutine in the process. Do not adopt it to use multiple CPU cores, which is amphp/parallel's job, or expecting it to ship its own event loop, since it now uses Revolt instead. Before committing, check your own dependency tree for stray blocking calls such as a synchronous database or filesystem path, because the README warns that any blocking I/O function blocks the entire process.
Frequently asked questions
What is amphp/amp and what does it replace?
It provides futures and cancellations as fundamental primitives for asynchronous programming in PHP. It replaced generator based coroutines with fibers, which PHP 8.1 shipped, making Amp\call() boilerplate unnecessary.
Why does amphp/amp require revolt/event-loop separately?
Because amphp/amp no longer ships an event loop implementation and uses Revolt instead. The README says to require it separately even when it is automatically installed as a dependency, since Revolt handles coroutine suspension and resumption.
Why does a Future not have a then method?
That absence is the reason amphp/amp chose the name Future over promise. Futures are meant to be awaited inside coroutines, with methods available that act on the result and return another future.
What PHP version and extensions does amphp/amp require?
PHP 8.1 or later, with no extensions required. Extensions are only needed when the app needs a high number of concurrent socket connections, with the file descriptor limit usually configured up to 1024.
Does amphp/amp use multiple CPU cores?
No. Coroutines are cooperatively scheduled and only one runs at a time. Using multiple cores and offloading blocking operations is the job of amphp/parallel.
What happens if a coroutine performs blocking I/O in amphp/amp?
A blocking I/O function blocks the entire process while waiting, so every other coroutine stalls with it. That is why the surrounding libraries avoid blocking for I/O.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/amphp-amp)Star history chart for your README
[](https://hysenlabs.com/projects/amphp-amp)Was this useful?