﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,difficulty
1990,Memory leak in elgglib.php,mdupont,,"On a 200+ users on ELGG 1.6.1 website, from time to time the front page became unaccessible and we had a PHP fatal error for memory limit exhausted.

Increasing the PHP memory limit fixed the problem for a while, until the same problem appeared (a few days later) and that we had again to increase the memory limit. At a point we had to allocate hundreds of megabytes for ELGG not to throw an error, and PHP was eating so much memory that it could cause the server to crash.

We tried to ajust Apache, PHP, MySQL and Memcache configuration without success.

The PHP error indicates that the culprit is in engine/lib/elgglib.php at line 1795. Here is the block of code : 

                        // [Marcus Povey 20090217 : Now retrieving all datalist values on first load as this saves about 9 queries per page]
                       $result = get_data(""SELECT * from {$CONFIG->dbprefix}datalists"");
                        if ($result)
                        {
                                foreach ($result as $row)
                                {
                                        $DATALIST_CACHE[$row->name] = $row->value;
                                
                                        // Cache it if memcache is available
                                        if ($datalist_memcache) $datalist_memcache->save($row->name, $row->value);
                                }
                                
                                if (isset($DATALIST_CACHE[$name]))
                                        return $DATALIST_CACHE[$name];
                        }

Just below this block, on line 1808 - 1815 is commented the old version of the code. After uncommenting this block and commenting the one above, ELGG was running again into 64 Mo of PHP memory AND page display was quicker than before. The code is : 

                        if ($row = get_data_row(""SELECT value from {$CONFIG->dbprefix}datalists where name = '{$name}' limit 1"")) {
                                $DATALIST_CACHE[$name] = $row->value;

                                // Cache it if memcache is available
                                if ($datalist_memcache) $datalist_memcache->save($name, $row->value);

                                return $row->value;
                        }

It turns out that saving queries wasn't the best way to increase performance and stability. Since this block of code is still here in 1.7, it should be corrected or reverted back to the old version.",Defect,closed,high,,Core,1.6,critical,worksforme,"memory leak, elgglib.php, engine",brettp,
