$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.236

Latest news

  • ProcessWire Weekly #554
    In the 554th issue of ProcessWire Weekly we'll check out the latest core updates, introduce a couple of new third party modules, and more. Read on!
    Weekly.pw / 21 December 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH