What are Fibers in PHP, and how do they enable 'cooperative multitasking' without being true threads?
Last updated
Fibers (PHP 8.1) are pausable functions:
new Fiber($callable)thenstart(),Fiber::suspend($value)to pause, andresume($value)to continue.Multitasking is cooperative: a Fiber runs until it voluntarily suspends and is never interrupted, so only one touches memory at a time (no locks or races).
They are not threads: all Fibers share one thread and core. They are a low-level primitive usually driven by
AMPHPorReactPHPevent loops.
- https://www.php.net/manual/en/language.fibers.php
- https://www.php.net/manual/en/class.fiber.php
- https://codewithkyrian.com/writing/php-fibers-the-missing-piece-for-elegant-cooperative-multitasking/
- https://dev.to/gabrieloliverio/concurrency-and-parallelism-in-php-part-1-21m5
- https://itsimiro.medium.com/understanding-fibers-in-php-a-new-way-to-handle-concurrency-ed07424320ff
- https://synpass.pro/case-studies/mastering-php-fibers-harnessing-concurrency-for-modern-php-applications/
- https://php.watch/versions/8.1/fibers
- https://aoeex.com/phile/php-fibers-a-practical-example/