Skip to content

Cursor Pagination

Walk through large Doctrine ORM result sets in fixed-size pages. Each page starts after the last row of the previous one instead of skipping rows with an OFFSET, so page 10,000 costs the same as page 1.
Terminal window
composer require silarhi/cursor-pagination

Keyset pagination

Each page is fetched with a WHERE clause built from the last row of the previous page, never an OFFSET.

Multi-field ordering

Combine several fields, each ascending or descending, ending with a unique one.

Item or chunk iteration

Iterate entity by entity, or by arrays of maxPerPages items for flush and clear batches.

Restartable iterations

Every iteration starts from the beginning with its own cursor, even if a previous one was stopped early.

Fetch joins handled

One query per page, or two when the query joins a collection or another entity (JOIN … WITH): the page’s ids, then their rows.

Query analysis

Collection joins and scalar rows are detected; misconfigured orders throw instead of skipping rows.

Counting

count() and getNbPages(), with a plain COUNT when no join can duplicate rows.