Re: DB_DataObject in a daemon

From: Date: Thu, 24 Mar 2005 20:51:49 +0000
Subject: Re: DB_DataObject in a daemon
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18317@lists.php.net to get a copy of this message
On Thu, 24 Mar 2005 12:33:55 -0700, Trevan Devaun Richins <tdr@cs.byu.edu> wrote: > We have a script that is running as a daemon and uses DB_DataObject. > After the daemon has been running for a few days, we get an out of > memory error in PHP. I have been trying to track down what could > possibly be causing the memory leaks. I have called free on all the > DO's and then unset them and made them null. I have also tried to clear > all the globals that PEAR and DB_DataObject is using. I was just > wondering if any of you have any ideas on what could be causing the > memory leak. > > This is the main loop that is running most of the time as it waits for > changes: > > while (1 && $ready) { > > $db = DB_DataObject::factory('updateall'); > $db->query($status_sql); > $db->fetch(); > > $current_time = date('Y-m-d H:i:s'); > > $update = old_update($db->Rows, $db->Update_time); > > // if there has been a change, go do it > > if ($update) { > // print out the date we were run (for logging purposes) > echo get_time($current_time, true). " - Starting update > script...\n"; > $result = main_updateall_loop(); > // if $result isn't true, we have an error > if ($result !== true) { > $result->writeLog(); > > if ($result->getLevel() === UA_CRITICAL) { > // critical error, lets leave > ob_end_flush(); > exit(); > } > } > } else { > $time = get_time($current_time); > // if there is something to print, appendMessage > if ($time != '') { > echo $time ." - No updates to make\n"; > } > } > // just make sure it is all out there > while (ob_get_level() > 0) { > ob_end_flush(); > } > > // we've got to free up some memory > $db->free(); > unset($db); > $db = null; > > // used by PEAR that is never cleared > unset($_PEAR_destructor_object_list); > $_PEAR_destructor_object_list = null; > > unset($GLOBALS['_DB_DATAOBJECT']); > $GLOBALS['_DB_DATAOBJECT'] = null; > sleep(1); > } > > As you can see the only thing that is created in this loop is a > DB_DataObject. This loop is run 80% of the time (it only goes on if the > Database was changed which is pretty rare). > > If you have any ideas, I would appreciate them. > Whya re you using DB_DataObject for this? I don't see any usage of any real DB_DataObject's functionality (although I suppose you *could* be doing something special in $db->fetch()...). You're also using query() instead of using DB_DO's query building functionality, so all you're using it for is a data container. I suggest you change your script to use DB directly, fetch an assoc, and then free whatever you can. It will be much simpler and easier to track down leaks than with DB_DO, which does a lot more than you need here. -- Justin Patrin

« previous php.pear.general (#18317) next »