dev-master
9999999-dev https://github.com/jlorente/yii2-helpersA collection of Yii2 helpers with a variety of purposes
MIT
by Jose Lorente Martin
helpers collection yii2 helper iterator
A collection of Yii2 helpers with a variety of purposes
A collection of Yii2 helpers with a variety of purposes, (*1)
QueryStreamIterator - Provides an Iterator for large query resultsets that are likely to spend a large amount of memory., (*2)
Include the package as dependency under the bower.json file., (*3)
To install, either run, (*4)
$ php composer.phar require jlorente/yii2-helpers "*"
or add, (*5)
... "require": { // ... other configurations ... "jlorente/yii2-helpers": "*" }
to the require
section of your composer.json
file., (*6)
Imagine you have a table of cities with 1000000 rows and you want to iterate over all of them. Performing a normal query you will fetch 1000000 results at the same time and the memory consumption will increase., (*7)
This iterator allows you to wrap a QueryInterface object inside it and iterate over the whole resultset, but only fetching the number of results that you establish at the same time., (*8)
i.e.:, (*9)
use jlorente\helpers\QueryStreamIterator; $cities = new QueryStreamIterator([ 'query' => City::find(), 'dataStreamSize' => 500 ]); foreach ($cities as $city) { echo $city->name . PHP_EOL; }
Where the query property is the QueryInterface object and the dataStreamSize is number of results to fetch at the same time. You have to consider that the higher this number is, the higher the Iteration speed, but the memory comsumption will be also higher and vice versa., (*10)
Copyright © 2015 JosĂ© Lorente MartĂn jose.lorente.martin@gmail.com. Licensed under the MIT license. See LICENSE.txt for details., (*11)
A collection of Yii2 helpers with a variety of purposes
MIT
helpers collection yii2 helper iterator