PHP Fibers
summary
Claim: Fibers in PHP 8.1 let single-threaded code suspend and resume so async I/O looks synchronous. Demonstration builds a proof‑of‑concept framework: an event loop, non-blocking streams (stream_set_blocking(false)), socket readers, a URL fetcher that yields and resumes fibers, and a defer helper. Result: two-file download moves from 32 to 20 time units by overlapping waits, removing nested callbacks and making async code act like ordinary return/throw, at the cost of userland scheduling because fibers are cooperative not threads.
AI-written summary · about
chapters (22)
- 0:00Introduction
- 2:47Fibers
- 7:06Reflection class
- 10:05Nesting
- 11:51How it works
- 14:47Task
- 15:24File Download
- 17:49File Download Graph
- 24:25Global Loop
- 28:50Fetcher
- 29:31Big Function
- 31:32Asynchronous
- 31:49Callback Hell
- 32:32Bring in the fibers
- 32:42FetchUrl
- 33:34defer
- 33:55refactor
- 34:59recap
- 37:47compare to generators
- 39:17fibers are not threads
- 42:59Questions
- 45:57Programmer control
related talks
39mUnlock Parallel Processing in PHP with Fibers
25mAsync PHP with Coroutines: Building Scalable Applications
01h 01mWhat's new in PHP 8.1
48mCooperative multitasking with generators
57mWhat's New in PHP 8.1 and 8.2
38mAsync advantage with Sync simplicity
39mWhat’s Wrong with Asynchronous PHP?
41mNew Feature: What the Fibers extension can do for you
