← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Fibers in Practice (Revolt / Amp)

PHP PHP 8.1+ Advanced
debt(d7/e5/b7/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate phpstan is the available tool but automated detection is explicitly marked 'no'. Mixing blocking I/O inside an event loop or leaked fibers from missing cancellations will not be flagged by phpstan automatically — these manifest as stalls or memory leaks only under load or in production, requiring careful review or runtime profiling to catch.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests unifying on Revolt as the standard event loop foundation, but common_mistakes include mixing blocking I/O throughout a codebase and missing cancellations on futures across many call sites. Fixing these patterns requires identifying and refactoring every blocking call and every long-running future in the async code paths, spanning multiple files within the async component.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (d7). Applies_to is limited to cli and queue-worker contexts (not all PHP), but within those contexts the event loop choice is deeply load-bearing — every async library integration, I/O call pattern, fiber lifecycle decision, and cancellation strategy is shaped by the Revolt model. Mixing ecosystems or changing the concurrency model later would require significant rework of all async code.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states developers believe Revolt makes PHP truly asynchronous like Node.js with parallel execution, when in fact it is single-threaded cooperative concurrency. This contradicts mental models from Node.js, Go, or other async runtimes where I/O truly overlaps. The 'obvious' assumption of parallelism leads directly to race-condition-free but also performance-incorrect code, and blocking calls silently stall the entire loop — a documented but widely misunderstood gotcha.

About DEBT scoring →

Also Known As

Revolt event loop PHP async event loop amphp revolt

TL;DR

Using PHP 8.1 Fibers with event-loop libraries like Revolt or Amp to write non-blocking concurrent code in a synchronous, readable style.

Explanation

PHP 8.1 Fibers provide cooperative concurrency — a Fiber can suspend itself and be resumed, letting an event loop interleave multiple I/O-bound tasks without OS threads. Revolt (successor to ReactPHP's event loop) and Amp v3 build on Fibers to provide async HTTP clients, database drivers, and file I/O. Unlike promise chains, Fiber-based code reads top-to-bottom like synchronous code. Ideal for PHP CLI services, queue workers, and real-time applications with many concurrent connections. For highest throughput, evaluate Swoole or RoadRunner which use multi-threading rather than cooperative multitasking.

Common Misconception

Revolt makes PHP truly asynchronous like Node.js. Revolt provides an event loop built on PHP Fibers but PHP remains single-threaded — I/O callbacks are interleaved cooperatively, not executed in parallel. True parallelism still requires separate processes.

Why It Matters

Revolt is the event loop that powers PHP async frameworks like ReactPHP and Amp — understanding its suspend/resume model is essential for writing non-blocking PHP without race conditions.

Common Mistakes

  • Mixing blocking I/O calls inside a Revolt event loop — one blocking call stalls the entire loop.
  • Not using cancellations on long-running futures — leaked fibers hold memory indefinitely.
  • Expecting parallelism — Revolt is single-threaded cooperative concurrency, not multi-threading.
  • Using Revolt for simple scripts where a synchronous approach is clearer and sufficient.

Code Examples

✗ Vulnerable
// Blocking call inside async context — stalls the event loop:
Revolut\EventLoop\run(function(): void {
    $data = file_get_contents('https://api.example.com'); // Blocks!
    echo $data;
});
// Use amphp/http-client or ReactPHP HTTP client instead
✓ Fixed
// Revolt event loop — cooperative concurrency (PHP 8.1+)
use Revolt\EventLoop;

EventLoop::delay(1.0, function(): void {
    echo "Fires after 1 second\n";
});

EventLoop::repeat(0.5, function(): void {
    echo "Fires every 500ms\n";
});

// Amp v3 — Fiber-based async I/O
use Amp\async;
use Amp\Future;

$a = async(fn() => slowOperation());
$b = async(fn() => anotherOperation());
[$resultA, $resultB] = Future\await([$a, $b]); // concurrent

EventLoop::run();

Added 15 Mar 2026
Edited 22 Mar 2026
Views 59
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 2 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 7 Scrapy 6 Ahrefs 5 ChatGPT 5 SEMrush 5 Perplexity 4 Google 3 PetalBot 3 Unknown AI 2 Majestic 1 Bing 1 Meta AI 1 Twitter/X 1 Applebot 1 Brave Search 1
crawler 42 crawler_json 4
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
PHP php A server-side scripting language that generates web pages and APIs — the code runs on the server, and only its output (usually HTML or JSON) reaches the browser.

PHP is often the first server-side language people meet, and understanding its execution model — script starts fresh on every request, no memory between requests — explains most of how the web backend works: sessions, databases, and caching all exist to bridge that per-request amnesia.

💡 Start with PHP 8.x, declare(strict_types=1), and PDO — skip any tutorial that mentions mysql_query().

Ask Codex about PHP →
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: High
⚡ Quick Fix
Use Revolt as the standard event loop foundation — Amp v3 and ReactPHP both run on it, so libraries from both ecosystems can share one loop
📦 Applies To
PHP 8.1+ cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Mixing Amp and ReactPHP in same project causing two event loops; raw Fiber usage without event loop scheduler
Auto-detectable: ✗ No phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant