On 31 mayo, 13:25, StinkyTofu <[EMAIL PROTECTED]> wrote:
> I am calling $this->Member->findAll(null, 'Member.id') on a database
> of 8000 records and am receiving the following error:
>
> Allowed memory size of 16777216 bytes exhausted (tried to allocate 782
> bytes) in /home/web88/html/cake/libs/model/datasources/dbo_source.php
> on line 312
>
> I assume this error is happening because the server is loading too
> many records into the array.  The issue here is that I need to take
> all the member records and insert them into a .csv file, so I cannot
> use the SQL 'LIMIT' function as that will mean that only a portion of
> the records will be imported into the csv.
>
> Just wondering if I am taking the right approach here or if there is a
> function in CakePHP which will allow me to load one record at a time
> and then iterate through the records in the database to avoid loading
> all the records into one array at a time?  If not, is there a best
> practice in CakePHP to deal with this kind of problem?  I was thinking
> of using a for next loop in combination with findAll() using the SQL
> 'LIMIT' function to keep the returned records to a limit of 50, and
> then looping through the database this way until all the records have
> been processed.  I just wasn't sure if this is the right approach to
> take, it seems like a messy work-around.

Reducing the fields/association of what you ask for can't hurt but
using a limit and looping is how large (batch) processes usually work.

Applied to cakephp I guess it would be:

$this->ModelName->cacheQueries = false;
while ($this->ModelName->hasAny($constraint)) {
     $results = $this->ModelName->findAll($constraint,null,null,50);
     foreach ($results as $result {
          // some processing which means this row will not be returned
in any subsequent findAlls
     }
}

OR

$count = $this->ModelName->findCount($constraint);
$limit = 50;
$lastPage = ceil($count / $limit );
$page = 1;

while ($page <= $lastPage) {
     $results = $this->ModelName->findAll($constraint,null,null,
50,$page};
     foreach ($results as $result {
     }
     $page++;
}


hth,

AD


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to