Amp ⋅ Introduction
Amp is a non-blocking concurrency framework for PHP. It provides an event loop, promises and streams as a base for asynchronous programming.
Promises in combination with generators are used to build coroutines, which allow writing asynchronous code just like synchronous code, without any callbacks.
composer require amphp/amp
The weak link when managing concurrency is humans; we simply don’t think asynchronously or in parallel. Instead, we’re really good at doing one thing at a time and the world around us generally fits this model. So to effectively design for concurrent processing in our code we have a couple of options:
- Get smarter (not feasible);
- Abstract concurrent task execution to make it feel synchronous.
Start with the Introduction to Event Loops.