简体   繁体   中英

Writing large dynamic arrays/objects to text formatted log files

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM