Guy Verville Posted May 12, 2018 Share Posted May 12, 2018 First of all, I'm not an expert on PHP. I recently read about generators and I understand their usefulness in avoiding loading a set of objects into an array to the point of saturating the memory. The $pages->find() call is known to be greedy (and slow) when it comes to processing large amounts of pages, because it loads all objects into memory. Is there a way to use a generator to avoid this problem? Is there a workaround? I know that $pages->findMany() exists, but it is also called greedy. See https://secure.php.net/manual/en/language.generators.php Translated with www.DeepL.com/Translator Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 14, 2018 Share Posted May 14, 2018 Generators are PHP 5.5+ so it won‘t fit for ProcessWire, which is still running down to PHP 5.3. But the new $pages->findMany() works similarly to how generators work. 2 Link to comment Share on other sites More sharing options...
Guy Verville Posted May 15, 2018 Author Share Posted May 15, 2018 I was under the impression that findMany() was loading everything into memory. Maybe I'm wrong... I will do some tests, thanks. Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 16, 2018 Share Posted May 16, 2018 The reason for adding findMany() was to not load all pages into memory like find() does. It does so by harnessing PHP iterators to load batches of pages within a foreach loop and discard already computed batches to free up memory again. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now