Ejemplo n.º 1
2
 /**
  * Check if I have to clean the memory or not. That should be call by the
  * functions that do a Save or any kind of retrieve (getBean, get_list ...)
  *
  * @return boolean Operation was succesful
  */
 private function cleanMemory()
 {
     $usedMemory = round(memory_get_usage() / 1024 / 1024, 0);
     if ($usedMemory > 250 && $this->loopWithoutCleaningMemory > 300) {
         BeanFactoryCache::clearCache();
         $this->loopWithoutCleaningMemory = 0;
         $msg = "Memory Cleaned because usage is around {$usedMemory} Mib. ";
         $msg .= 'Collected ' . gc_collect_cycles() . ' cycles.';
         $this->getLogger()->warning($this->logPrefix . $msg);
     } else {
         $this->loopWithoutCleaningMemory++;
     }
     return true;
 }
 public function testRightInstanciation()
 {
     // first load a bean
     $entryPoint = $this->getEntryPointInstance();
     // My beans are empty: I have never loaded anything
     BeanFactoryCache::clearCache();
     $loadedBeans = BeanFactoryCache::getLoadedBeans();
     $this->assertEmpty($loadedBeans);
     $DBTest = new DBTest();
     $sugarDB = $DBTest->rightInstanciation();
     $sugarBean = new Bean($entryPoint, $sugarDB);
     $sugarBean->getBean('Users', 1, array(), true, true);
     // Now it contains something
     $loadedBeans = BeanFactoryCache::getLoadedBeans();
     $this->assertNotEmpty($loadedBeans);
     // Now it's empty again
     BeanFactoryCache::clearCache();
     $loadedBeans = BeanFactoryCache::getLoadedBeans();
     $this->assertEmpty($loadedBeans);
 }