Bilge / Fibers-test

Contrived PHP fibers test using Amp v3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fibers test

PHP 8.1 packs a lot of great features, but among them, the most interesting are fibers. Fibers allow us to work asynchronously in PHP without the cumbersome boilerplate of the prior state-of-the-art using coroutines. Of course, we still need a task scheduler built on top of fibers, and for this we defer to the excellent Amp. Although Amp's support for fibers is still in beta and documentation is missing, its APIs are intuitive enough to follow.

This project is the PHP analog of my Go concurrency test which implements the same pattern: spawn a web server that responds with incrementing integers starting at 1 and query it n (typically 10) times and observe the numbers are emitted in a pseudo-random order. In Go, this pseudo-random order occurs naturally because Go has "real" concurrency semantics. In PHP, its single-threaded design means our contrived example has deterministic output, that is, the output is a contiguous integer sequence. We simulate randomness by introducing an arbitrary delay before sending the response in the order of ⅒th → 1 second on each request.

About

Contrived PHP fibers test using Amp v3


Languages

Language:PHP 100.0%