Reputation: 2173
For a few years I have been using Magento as my ecommerce site platform.
But I sometimes get really fed up when I see lack of PHP Functions, like print_r
or var_dump
, to handle writing large object/array to a log file(when printing this much data on Browser is already out of question).
For example when I have to check(debug what is it's outline and what data it holds) a large collection object(or object containing a lot of other objects due to dependencies) like category-collection
or product-collection
, if I run below code:
$collection = Mage::getModel('catalog/category')->getCollection();
or
$collection = Mage::getModel('catalog/product')->getCollection();
Mage::log(print_r($collection, true), null, 'developer.log');
Then many times I get error Allowed memory size of ######## bytes exhausted ...
, especially when doing live projects(live websites hosted on Shared servers).
So in wake of this I really need a core-php suggestion about how to write large object/arrays like Magento collections to text log files without PHP Engine running out of memory and without needing to install Xdebug or other external utilities.
How(if I can) can I use buffering
or string splitting
in this scenario ?
Upvotes: 0
Views: 39
Reputation: 135
Most likely you do not need the entire collection entity logged into a file, but $collection->getItems()
.
There might be recursions in properties of your collections objects, so they cannot not be properly var_dump'ed.
Upvotes: 1