dmitry_kv22 Nov 2025 22:42

I understand Fibers conceptually. I know ReactPHP and Amp use them. What I cannot find is good examples of writing application-level code with Fibers that does not require learning a full framework.

Specifically: making two database queries in parallel without Swoole or Amp.

Replies (5)
alex_petrov22 Nov 2025 22:59

You cannot easily do parallel DB queries with vanilla Fibers because PDO and mysqli are blocking. Fibers suspend cooperatively but they do not make synchronous I/O non-blocking. You need non-blocking IO primitives, which means an event loop.

0
dmitry_kv23 Nov 2025 00:45

The short answer: Fibers are useful for writing async code that reads synchronously, but you still need an event loop driving them for actual concurrency. Without an event loop, you get cooperative multitasking but not parallelism.

0
sergey_web23 Nov 2025 01:18

Amp 3 is the lightest-weight option if you want to avoid Swoole. It is event-loop driven with a clean API and you can use it without adopting a full framework. The postgres and mysql drivers are non-blocking.

0
nphp23 Nov 2025 03:14

For parallel queries without any async tools: PDO + pcntl_fork, run each query in a child process, collect results in the parent. Ugly but requires no extensions beyond PCNTL.

0
vova23 Nov 2025 03:32

The simplest actual use case for Fibers in application code I found: generators-as-coroutines for streaming data transformation. You yield data at each step and the caller drives the execution. No I/O concurrency, just composable lazy sequences.

0
Write a reply
Markdown. ```php blocks are runnable.