dmitry_kv20 Apr 2025 22:42

Fibers landed in PHP 8.1 but most discussion is about how frameworks use them internally. What are useful patterns for application code?

I am writing a CLI tool that needs to do parallel HTTP requests. Considering Fibers vs just using curl_multi.

Replies (6)
alex_petrov20 Apr 2025 22:47

curl_multi is fine and battle-tested. Fibers do not add much on top of it unless you want to compose async operations in a readable way. The real value of Fibers is that you can write code that looks synchronous but suspends at IO points, which is more readable than callback chains.

0
dmitry_kv21 Apr 2025 00:17

For a CLI tool doing parallel requests I would reach for ReactPHP or Amp before rolling my own Fiber scheduler. They handle the event loop, error propagation, and cancellation. Fibers are the primitive; the libraries are the usable abstraction.

0
nphp21 Apr 2025 01:36

One practical Fiber pattern for CLI: a simple cooperative scheduler. Create one Fiber per task, run each until it suspends, continue others. No external dependencies and works for CPU-light IO-heavy workloads.

0
sergey_web21 Apr 2025 01:57

Amp v3 is built on Fibers and the API is clean. Worth looking at for async CLI work. The HTTP client in Amp handles concurrent requests naturally.

0
katedev21 Apr 2025 03:43

I tried to implement a Fiber scheduler from scratch. Got it working but error handling and cleanup on exceptions is subtle. The edge cases are not obvious. Unless you need zero dependencies, use a library.

0
alex_petrov21 Apr 2025 04:41

That is a fair point. The resume/throw interaction between fibers and the suspend point is not trivial to get right. ReactPHP promise chains are verbose but the error semantics are explicit.

0