One of my clients recently reached out to me because they were having some issues with a Magento site that was using Memcache to store user sessions. The website recieves about 6,000 or so unique visitors a day and the session data was filling up their memcache and causing a number of hosting/website issues, like user sessions not working and carts being deleted.
They had done a little bit of debugging by the time they brought me in and said it seemed like page content was being stored in the session, along with the normal Magento visitor session data. On average, user sessions were around 1.5MB, so at 6,000 unique visitors, there was close to 9GB of session data being generated each day.
I started by switching over to using files, instead of memcache, for session data, so I could more easily test/debug. I inspected a few and there was a lot of HTML being stored in the session. After a bit more digging, I determined that it wasn’t actually the page the user was necessarily on, but rather the category descriptions and other text related to their categories that was being stored as an array called ‘category_tree.’
Armed with this knowledge, I did a search of the app/code/local, app/code/community, and app/design/frontend folders for modules that were setting session data and specifically for ‘category_tree’ and ‘categoryTree’
I found that this was being saved to the session as part of a plugin created by Magebay called Menu Creator Pro.
I haven’t dug too deep yet, but as part of the plugin’s process, it saves a complete copy of categories(or at least the ones being used in the menu) to each user’s session. On this site, they had very long html descriptions, which was the HTML being seen in the session files.
Magento user session files/data were very big and included HTML from what appeared to be page content, but was actually category descriptions and other category data. This was due to the way the Menu Creator Pro saves data to user’s sessions.
As a quick fix, I edited code/local/MST/Menupro/Block/Base.php as follows(see the “MOD” comment):
if (!$categoryTree || $currentStoreViewCode != $currentCode) { //die('Correct... Testing ... ' . $currentCode); $categories = $this->categoryObject->getCategories(); foreach ($categories as $category) { $catData = $category->getData(); /*MOD*/ unset($catData['description']); unset($catData['more_content']); unset($catData['umm_dd_blocks']); unset($catData['additional_description']); /*MOD*/ //Sorted child $allChild = $category->getChildrenCategories(); $childString = ""; if (count($allChild) > 0) { $child = array(); foreach ($allChild as $cate) { $child[] = $cate->getData('entity_id'); } //print_r($child); $childString = join(',' , $child); } $catData['children'] = $childString; $allCategories[$category->getEntityId()] = $catData; } Mage::getSingleton('core/session')->setCategoryTree($allCategories); Mage::getSingleton('core/session')->setCurrentStoreViewCode($currentCode); $this->_tree = $allCategories; } else { $this->_tree = $categoryTree; }
By unsetting $catData[‘description’], $catData[‘more_content’], $catData[‘umm_dd_blocks’], $catData[‘additional_description’], I was able to reduce the size of the session file from around 1.5MB to .75MB.
This is still quite large, as I checked another Magento site I manage and their sessions were all in the 4K-12K range. However, I think it is enough to keep them from having the memcache isssues in the short term.
We have reached out to the plugin developers and if they can’t/won’t fix or don’t reply, will likely disable and replace the plugin or if it ends up being heavily utilized, switch to saving the category data in Magento’s cache, rather than user sessions, which is where I believe it should have been stored in the first place.
Add a Comment