If one request takes 1s in I/O waiting Each worker can handle only one request and the same time Concurrency in PHP depends on worker numbers Context switch between processes are expensive! request request request
to implement simple iterators Generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory Generator can yield as many times as it needs to provide the values to be iterated over (From official PHP manual)
coroutines Coroutines can control where execution continues immediately after they yield, while Generators cannot, instead transferring control back to the generator's caller The yield statement in a generator does not specify a coroutine to jump to, but rather passes a value back to a parent routine (From Wikipedia)
ret2 NULL the first var_dump in gen the var_dump of the ->send() again from within gen the return value of ->send() (https://www.npopov.com/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html)
Amp Unlike stack-less Generators, each Fiber has its own call stack, allowing them to be paused within deeply nested function calls Execution may be interrupted anywhere in the call stack using Fiber::suspend() Once suspended, execution of the fiber may be resumed with any value using Fiber::resume() (From official PHP manual)
comprehensive coroutine rather than semi-coroutine Eliminates yield statement for coroutines Fiber doesn't turn your code into non-blocking magically, traditional blocking code has to be rewritten for asynchronous I/O Help not too much for most of developers Fiber provides only bare minimum required to allow user code to implement full-stack coroutines in PHP Fiber doesn't support Preemptive Scheduling yet
difference between Generator and Fiber? How to turn Blocking I/O stream turning into Non-Blocking? What is Event Loop? Is it required for Asynchronous? What's the benefits of Coroutine? Is Asynchronous a must for Coroutine? How to make built-in Blocking I/O functions Asynchronous? Can Asynchronous I/O be integrated with traditional Blocking I/O environment? (e.g. PHP-FPM)
Blocking I/O functions can be replaced to Non-Blocking I/O automatically if hook flags are set Swoole supports Preemptive Scheduling for CPU-bound tasks Swoole Provides CSP Model for Coroutine Communications like in GoLang Yields and resumes take place behind the scenes for I/O functions switching