Exploring Coroutines in PHP
The term "coroutine" often comes up when talking about asynchronous or non-blocking code, but what does it actually mean?
Read more [doeken.org]
Posts tagged with generators
The term "coroutine" often comes up when talking about asynchronous or non-blocking code, but what does it actually mean?
Read more [doeken.org]
– doeken.org - submitted by Doeke Norg
The term "coroutine" often comes up when talking about asynchronous or non-blocking code, but what does it actually mean? In this post, we will explore coroutines as a concept and see how PHP supports them through Generators and Fibers.
Read more [doeken.org]
Join thousands of developers
Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.
No spam. Unsubscribe anytime. You can also follow me on X.
An article explaining PHP's yield keyword and how it can be use in place of return to easily build iterators.
Read more [ides.dev]
– www.crwlr.software - submitted by Christian Olear
Since working with generators can be a bit tricky if you're new to them, this post offers an intro on how to use them and highlights common pitfalls to avoid.
Read more [www.crwlr.software]
– bannister.me - submitted by James Bannister
A post outlining how you can use generators, and LazyCollections, to create better interfaces for paginating APIs.
Read more [bannister.me]
– doeken.org - submitted by Doeke Norg
This post exmplains how you can work with iterators and generators as if they were arrays.
Read more [doeken.org]
– doeken.org - submitted by Doeke Norg
Yield better results by iterating over generators. Learn more about these supercharged arrays that can preserve memory.
Read more [doeken.org]
Here's a little tip: you can use `yield` in phpunit data providers to make them a little more readable pic.twitter.com/rQeKw7jBed
— Brent (@brendt_gd) 12 december 2019
Read more [twitter.com]
In a new blogpost published at Sitepoint, Christopher Pitt explores the various ways you can handle reading big files in PHP.
Though this isn’t a problem we frequently suffer from, it’s easy to mess up when working with large files. In asynchronous applications, it’s just as easy to bring the whole server down when we’re not careful about memory usage.
This tutorial has hopefully introduced you to a few new ideas (or refreshed your memory about them), so that you can think more about how to read and write large files efficiently. When we start to become familiar with streams and generators, and stop using functions like file_get_contents: an entire category of errors disappear from our applications. That seems like a good thing to aim for!
Though the generators look cool, I've never used them much because I didn't find a good use case. Evert Pot demonstrates on his blog how they can help conserve memory.
Since the release of PHP 5.5, we now have access to generators. Generators are a pretty cool language feature, and can allow you to save quite a bit of memory if they are used in the right places.http://evertpot.com/switching-to-generators/
Christopher Pitt experimented a bit with generators and wrote down the thought process on his blog.
https://medium.com/@assertchris/recursion-and-generators-d56f513ea6abGenerators are awesome. If they’re new to you then take some time to read where they come from and what they do. If you’ve come from a particular programming language background, they may be difficult for you to understand.
They were, and continue to be, tricky for me to grasp. So I’ve spent loads of time trying to understand them, and what they can do for my code.