Fibers provide a mechanism for suspending and resuming PHP execution. They are a low-level building block for cooperative concurrency and are used by libraries and runtimes that coordinate asynchronous operations. A Fiber does not automatically make ordinary blocking file, database or network calls non-blocking.
Understand suspension
A Fiber can suspend at a chosen point and later resume, allowing a scheduler or calling code to run other work in between. The application or library must decide when suspension is appropriate and how execution is resumed. This is different from preemptive multithreading: code does not get interrupted at arbitrary instructions.
Use an event loop or compatible library
For concurrent I/O, use a runtime or library designed to integrate non-blocking operations with a scheduler. Simply wrapping a blocking HTTP request in a Fiber still blocks the process while the request runs. Review the library's requirements and supported PHP version before adopting it.
Handle failures and cancellation
Exceptions thrown inside a Fiber must be handled at the appropriate boundary. Long-running tasks also need cancellation, timeouts and resource cleanup policies. Concurrency can expose race conditions even in a single-threaded event loop when operations interleave.
Decide whether it is worthwhile
Traditional PHP request-response applications may not benefit from Fibers directly. They are most relevant when building long-running workers, concurrent network clients or systems that depend on asynchronous libraries.
Checklist
- Distinguish suspension from automatic asynchronous I/O.
- Use a compatible scheduler for non-blocking operations.
- Define timeout, cancellation and cleanup behavior.
- Test exception propagation and interleaving.
- Adopt Fibers only when the workload benefits.