We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Running out of memory when doing find()

I have a table that contains 120,000+ records and when I do MyModel::find() on it, PHP is running out of memory. I assume it is reading the entire result set and creating model instances for each. But, according to the Phalcon documentation:

"One of the greatest features of the Phalcon\Mvc\Model\Resultset is that at any time there is only one record in memory. This greatly helps in memory management especially when working with large amounts of data."

Am I misunderstanding how the Resultset works? Is there a setting I need to set to get the Resultset to handle this? I am using MySQL.



555
Accepted
answer

I understand what my problem was now. Resultset works fine. The problem was that I was using the Resultset in a paginator which was causing the Resultset to load everything in an array. This link discusses it and the new QueryBuilder paginator that works differently: https://forum.phalcon.io/discussion/129/paginating-large-amounts-of-data#C818