~/talk

PHP Fibers

Talkat PHP UK Conference 2022 · 2022-02-16..02-18· [php]
slides:none on file

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

  1. 0:00Introduction
  2. 2:47Fibers
  3. 7:06Reflection class
  4. 10:05Nesting
  5. 11:51How it works
  6. 14:47Task
  7. 15:24File Download
  8. 17:49File Download Graph
  9. 24:25Global Loop
  10. 28:50Fetcher
  11. 29:31Big Function
  12. 31:32Asynchronous
  13. 31:49Callback Hell
  14. 32:32Bring in the fibers
  15. 32:42FetchUrl
  16. 33:34defer
  17. 33:55refactor
  18. 34:59recap
  19. 37:47compare to generators
  20. 39:17fibers are not threads
  21. 42:59Questions
  22. 45:57Programmer control
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.