$pages->findMany() method

Like find(), but with “lazy loading” to support giant result sets without running out of memory.

When using this method, you can retrieve tens of thousands, or hundreds of thousands of pages or more, without needing a pagination "limit" in your selector. Individual pages are loaded and unloaded in chunks as you iterate them, making it possible to iterate all pages without running out of memory. This is useful for performing some kind of calculation on all pages or other tasks like that. Note however that if you are building something from the result set that consumes more memory for each page iterated (like concatening a string of page titles or something), then you could still run out of memory there.

The example below demonstrates use of this method. Note that attempting to do the same using the regular $pages->find() would run out of memory, as it's unlikely the server would have enough memory to store 20k pages in memory at once.

Available since version 3.0.19.

Example

// Calculating a total from 20000 pages
$totalCost = 0;
$items = $pages->findMany("template=foo"); // 20000 pages
foreach($items as $item) {
  $totalCost += $item->cost;
}
echo "Total cost is: $totalCost";

Usage

// basic usage
$items = $pages->findMany($selector);

// usage with all arguments
$items = $pages->findMany($selector, array $options = []);

Arguments

NameType(s)Description
selectorstring, array, Selectors

Selector to find pages

options (optional)array

Options to modify behavior. See Pages::find() $options argument for details.

Return value

See Also


$pages methods and properties

API reference based on ProcessWire core version 3.0.135

Twitter updates

  • New post: A look at two new WireMail modules for sending email, plus details on how you can configure ProcessWire to use Gmail for sending email— More
    19 July 2019
  • New post: Version 3.0.135 of ProcessWire on the dev branch focuses on some .htaccess updates, adds clarity to debug mode, and improves upon the installer— More
    5 July 2019
  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019

Latest news

  • ProcessWire Weekly #271
    In the 271st issue of ProcessWire Weekly we're going to introduce two brand new WireMail modules, a new Textformatter module from BitPoet, and a brand new markup module from Chris Thomson. Read on!
    Weekly.pw / 20 July 2019
  • Two new WireMail modules and using Gmail with PW
    A look at two new WireMail modules for sending email, plus details on how you can configure ProcessWire to use Gmail for sending email.
    Blog / 19 July 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer