🐘 PHP Intermediate

What is PHP Fibers?

Why Interviewers Ask This

This tests whether you can apply PHP knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

Fibers (PHP 8.1) are units of concurrency that allow functions to be paused and resumed. They are PHP's implementation of coroutines at the language level. A Fiber can be paused mid-execution with Fiber::suspend($value) and resumed with $fiber->resume($value). Unlike threads, Fibers are cooperative — they yield control explicitly and run in a single thread. They enable non-blocking I/O patterns and are the foundation for asynchronous PHP frameworks like ReactPHP and Amp (v3+). Example: $fiber = new Fiber(function(): void { $value = Fiber::suspend("paused"); }); $result = $fiber->start(); $fiber->resume("hello");. Fibers are lower-level than async/await but enable async libraries to be built on top of them.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your PHP experience.