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条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示