doujiufutaog59220 2016-06-04 18:00
浏览 55

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

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 ?

  • 写回答

1条回答 默认 最新

  • dongxing2030 2016-06-08 10:50
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测