donglu5612 2009-10-15 12:25
浏览 23
已采纳

从PHP 4过渡到5的内存泄漏 - 任何提示?

I am porting a large web application to a shared web hosting environment. The app was written in PHP 4. The new environment has PHP 5.2.

For some reason, the application is leaking tremendous amounts of memory when running in PHP 5.2. I can literally watch memory usage going through the roof using memory_get_usage(), until it reaches the limit of 64 MB (which is very generous in a shared environment, the site used to run with 12 or 16 MB on PHP 4).

I suspect that this is a side-effect of something that has changed in PHP 5, most likely the handling of object references in arguments. However, the search for the particular behaviour(s) that cause(s) the leak is extremely difficult as the application is very complex, and partly not very well written (yes, it is mine).

As the app is installed on a shared webspace, I can not use the classical debugging facilities (as far as I know). I would very, very much like to avoid recreating the environment locally, as I am working on the project literally all day for some time.

So my questions are:

  • Does anybody know typical PHP4 => 5 transition pitfalls, especially when dealing with large amounts of objects, that might be the cause for my leak(s)

  • Does anybody know some kind of debugger-independent, script-only "graphical scope dump" tool for the variables used by PHP that might help me find out which variables are eating up these enormous amounts of memory?

  • 写回答

3条回答 默认 最新

  • dongxing5525 2009-10-15 13:22
    关注

    To solve this issue I would:

    1. Profile the script with xdebug+wincachegrind (or some other profiler) and/or firephp.
    2. Turn on the STRICT mode to get all the php error + notices.

    Doing that, you will be able to:

    • Optimize your code. (Removing the errors/warning/notices can speed up your code)
    • Clean your code. (Using the proper php5 object syntax can only be good for the performance).

    The object model totally changed from PHP4 to PHP5. For sure, the STRICT mode will tell you that you should not use an explicit "passed by reference".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大