I have a function which collect products parent categories:

function getParentCategories($catId, $catsList) {
            $category = Mage::getModel('catalog/category')->load($catId);
                $catsList[] = $category->getParentCategory()->getId();
                return $this->getParentCategories($category->getParentCategory()->getId(),$catsList);
            } else {
                return $catsList;

which cause high memory usage:

FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 72 bytes) in /app/code/local/Mage/Core/Block/Template.php on line 415" while reading response header from upstream...

memory limit is 4G !!!! and even this is not enough. Can you help me with this function?


1 Answer 1


You've written a procedural recursive method that has an exponentially growing array passed as an argument.

Just use $category->getPath() and explode by /

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.