DB getAll method has memory leaks

From: Date: Wed, 18 Sep 2002 07:03:03 +0000
Subject: DB getAll method has memory leaks
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-9142@lists.php.net to get a copy of this message
Hello, Lately I've been using the DB class (specifically the mysql extension) to do large amounts of queries (i.e. 30,000+ in a single script). I have since noticed and been able to track down some bugs which make the getAll method (at least for mysql) get slower progressively (about 2 seconds every 1,000 queries on my machine) and eventually error out because memory runs out. The problems with getAll are twofold: 1. In common.php in the getAll method there is a while loop that fills the result table. Before that while loop $this->pushErrorHandling(PEAR_ERROR_RETURN); is called, and then afterwards $this->popErrorHandling(); is called. The only problem is that in pushErrorHangling two things are pushed onto the stack, the default error mode and the passed in error mode (at least in 0.91-dev), but in popErrorHandling array_pop is only used once. This means that for each getAll call the $_PEAR_error_handler_stack gets one element larger, so after 10,000 getAll calls in a script it becomes too big and the script fails because the maximum memory limit is exceeded. 2. In mysql.php in the simpleQuery method (which getAll uses) there is this bit of code: if (is_resource($result)) { $numrows = $this->numrows($result); if (is_object($numrows)) { return $numrows; } $this->num_rows[$result] = $numrows; This num_rows variable is never used as far as I can tell, so I'm not sure why it's there. But either way, the problem is that for each query the $result variable increments so again after 10,000 getAll calls the num_rows variable is a huge array which causes the script to fail because of memory. So, these things would explain why getAll becomes progressively slower. I'm not sure if these are known bugs but I couldn't find anything about them either in the mailing lists or CVS so I thought I would let you all know. -Jason -- http://www.rustyparts.com/ puttin' some rust into it!

« previous php.pear.dev (#9142) next »