Async & await at the edge with ReactPHP

Click for: original source

PHP 8.1 is out and the hip new feature for non-blocking and asynchronous programming in PHP are fibers. In this post we’re going to explore them and see how we at ReactPHP will start with them at the edge. By Cees-Jan Kiewiet.

Fibers are also known as green threads and offer thread like functionality within the same process, also known as cooperative multitasking. Each process always starts with the main fiber and you can decide to spawn more.

The article then deals with:

  • async
  • await
  • Run your entire application a fiber
  • Request handler
  • Looking ahead

Fibers are awesome, but because we barely scratched the surface we, ReactPHP, will start using them at the edge only. But there is a problem with that, currently there is no way to cancel a fiber as we can do now with promises ($promise->cancel()). Good read!

[Read More]

Tags open-source apis php app-development web-development