Have you tried generators? It looks like you are trying to implement
coroutines.
You can learn more about cooperative multitasking in PHP on this awesome
post written by Nikic:
https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html
- Marcos
On Wed, Sep 26, 2018
I do not know if I can get the same result with the current PHP features
without taking many turns. So I thought of a feature that I'm initially
calling "interruptions" (similar to those that occur on a CPU).
Nowadays we have the Exceptions, which stop the execution of a function and
initiate a