[Solar-talk] Memory problems
Paul M Jones
pmjones at ciaweb.net
Tue Nov 13 07:35:13 CST 2007
On Nov 13, 2007, at 7:28 AM, Rodrigo Moraes wrote:
> Hmm, I'm running into memory problems trying to migrate a database
> using the model (using cli). But I'm really not sure if it is model
> related.
>
> The script is basically as follow:
>
> $select = Solar::factory('Solar_Sql_Select');
> $res = $select->from('table')->fetch('all');
>
> $model = Solar::factory('My_Model);
>
> foreach($res as $data) {
> $record = $model->fetchNew();
> $record->foo = 'bar';
>
> try {
> $record->save();
> } catch(Solar_Exception $e) {
> throw $e;
> }
> }
>
> After a while: "Fatal Error: Allowed memory size of 268435456 bytes
> exhausted (tried to allocate 40 bytes) in ..."
>
> I tried to unset($record) after save(), but the same happens - it dies
> after about 5 thousand records.
>
> So, should I do it differently? Can I count with cli for this? :-|
Long version:
<http://paul-m-jones.com/blog/?p=262>
Short version:
* Problem: PHP's memory handling does not work well with parent/child
circular relationships.
* Solution: call $record->__destruct() manually, then unset($record).
Yes, this is tedious and inconvenient. :-(
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the Solar-talk
mailing list