Robotusers CakePHP Chunk plugin

0.1.2 2020-08-21 06:52 UTC

This package is auto-updated.

Last update: 2021-11-21 09:23:30 UTC


Software License Build Status codecov

This plugin allows to chunk results retrieved from a database in order to save memory.


composer require robotusers/cakephp-chunk
bin/cake plugin load Robotusers/Chunk

Using the plugin

The plugin provides a custom ResultSet class which accepts Cake\ORM\Query instance.


$query = $table->find();
$results = new \Robotusers\Chunk\ORM\ResultSet($query);

foreach ($results as $result) {
    // do stuff

You can control how many elements are in one "chunk" (1000 by default):

$query = $table->find();
$results = new \Robotusers\Chunk\ORM\ResultSet($query, ['size' => 100]);

The plugin provides also a behavior with chunk() method:

$query = $table->find();
$results = $table->chunk($query, ['size' => 100]);