duanjia4097 2010-07-28 01:37
浏览 54
已采纳

用于调试PHP中的内存泄漏/使用错误的工具/技术

I've got a command line script that is running an array() of files through a loop, and using the file name as an argument to call a method on a helper object.

Each run through the script, PHP's memory_get_usage reports a larger and larger number

53294264
57019624
61374624
65699176
70230600
75157152
79900392
84630472
89359264
94300016
100031176
105202448
110360808
115777528
121146976
126784824
132366952

until I error out with a

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted

It's clear that something is leaking memory, or some sort of global/static storage area keeps being added to. What's the best way to debug this kind of error in PHP? Are there common situations where this occurs inadvertently in PHP? Does xDebug have some magic options that can help me pinpoint this? Other tools?

The best I've come up with is following the chain of execution and littering the codebase with calls to memory_get_usage() until I pinpoint the exact problem, but that seems like a tedious and inefficient approach.

  • 写回答

1条回答 默认 最新

  • dongqiao8421 2010-07-28 01:53
    关注

    It looks like Facebook's xhprof provides memory profiling at the function call level.

    (I have never used it, but really want to...)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题