Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework, pdo_mysql and problems with memory limit - Why?

I have the following set-up:

  • Zend Framework 1.10.8
  • database adapter: pdo_mysql
  • memory limit: 128MB
  • table type: myisam
  • table size: 4 MB
  • number of records: 22.000
  • number of columns: aprox. 70

I want to select everything from the table, which should be no problem at all:

$table = new Application_Model_DbTable_Foo();
$everything = $table->fetchAll();

Doing this I run into a "memory exhausted" problem.

I wrote a script using PDO_MYSQL without Zend Framework and the memory usage was fine and it worked all right.

So I must be missing something here. Any hint highly appreciated. :-)

like image 401
herrjeh42 Avatar asked Feb 15 '26 03:02

herrjeh42


2 Answers

22k rows alone can a significant amount of data, depending on what your script is doing. If increasing the memory limit isn't an option, you might want to try this. Grab 'chunks' of rows. You can do this with a LIMIT. Set your page size to something that fits in memory and then process that. Keep increasing your OFFSET until you've processed all your data.

like image 191
Chris Henry Avatar answered Feb 17 '26 17:02

Chris Henry


Thanx, everybody, for having a look at my problem. :-)

For further reference, if someone else has this problem, I ended up like this:

 $db = Zend_Db_Table_Abstract::getDefaultAdapter();
   $result = $db->query("SELECT * from footable");
   foreach ($result as $row) {            
           //print $row["field"]; 
  }
  unset($result);

... still considering to switch to the "get it in chunks using LIMIT x,y"-suggestion.

like image 25
herrjeh42 Avatar answered Feb 17 '26 15:02

herrjeh42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!