What are PHP Fibers, and how do they enable 'green threading' or concurrency without being true multi-threading?
Last updated
A
Fiber(PHP 8.1) is an interruptible function:Fiber::suspend()pauses it mid-execution andresume()continues it later, all on one thread.It is "green threading" because switching is cooperative (no preemption, no OS thread per task). Event loops like
AMPHPorReactPHPsuspend Fibers during I/O and resume them when data is ready.Only one Fiber runs at a time, so you get concurrency (overlapping I/O waits) but no parallelism and no shared-memory races.