Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Christopher Pitt:
Co-operative PHP Multitasking
Mar 30, 2015 @ 17:47:41

Christopher Pitt has posted a new article on Medium.com about when an "array is like an adventure" when in the context of co-operative PHP multitasking. In it he shows how to make code work asynchronously with out the use of extensions, only generators.

Last week I got the opportunity to share recent work with my colleagues, at SilverStripe. I was going to present Async PHP today, but since I covered ReactPHP last week; I decided to talk about something slightly different. So here’s a post about cooperative multitasking.

He starts with some basic arrays and other things that act like them and can be iterated through (Traversable). He talks about implementing custom iterators to act the same way and the use of IteratorAggregate to "cheat" a bit when making them. The he gets into generators, showing how they can be used to iterate similarly. He shows how it's possible to send data to a generator, throwing exceptions inside them and the use of "coroutines" to create asynchronous code. He builds up a queue system with this method and shows how they execute with some simple echo output. He also shows the use of RecoilPHP, another coroutine-based library, to replace the main kernel for a ReactPHP script. He also mentions IcicleIO as another option.

tagged: cooperative multitasking asynchronous code coroutine generator

Link: https://medium.com/@assertchris/co-operative-php-multitasking-ce4ef52858a0


Trending Topics: