简体   繁体   English

将大型动态数组/对象写入文本格式的日志文件

[英]Writing large dynamic arrays/objects to text formatted log files

For a few years I have been using Magento as my ecommerce site platform. 几年来,我一直使用Magento作为我的电子商务网站平台。

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). 但是,当我看到缺少诸如print_rvar_dump类的PHP函数来处理将大型对象/数组写入日志文件时,有时会感到非常var_dump (当在Browser上打印这么多数据时已经毫无疑问)。

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: 例如,当我必须检查(调试它的轮廓和所保存的数据)时,如果我在以下代码下运行,则一个大型集合对象(或由于依赖性而包含很多其他对象的对象),例如category-collectionproduct-collection 。 :

$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). 然后很多次我都报错Allowed memory size of ######## bytes exhausted ... ,尤其是在进行实时项目(共享服务器上托管的实时网站)时。

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. 因此,在此之后,我真的需要一个有关如何将大型对象/数组(如Magento集合)写入文本日志文件的PHP核心建议,而不会导致PHP Engine内存不足且无需安装Xdebug或其他外部实用程序。

How(if I can) can I use buffering or string splitting in this scenario ? 在这种情况下,如何(如果可以的话)可以使用bufferingstring splitting

Most likely you do not need the entire collection entity logged into a file, but $collection->getItems() . 您很可能不需要将整个集合实体登录到文件中,而是需要$collection->getItems() There might be recursions in properties of your collections objects, so they cannot not be properly var_dump'ed. 您的collections对象的属性中可能存在递归,因此不能正确进行var_dump'ed。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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