Posts tagged with generators

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.

How to Read Big Files with PHP (Without Killing Your Server)

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!

https://www.sitepoint.com/performant-reading-big-files-php/

Read more

Recursion and Generators

Christopher Pitt experimented a bit with generators and wrote down the thought process on his blog.

Generators 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.

https://medium.com/@assertchris/recursion-and-generators-d56f513ea6ab

Read more