从 PHP 4 到 5 的过渡过程中出现内存泄漏 - 有什么提示吗?
我正在将大型 Web 应用程序移植到共享 Web 托管环境。 该应用程序是用 PHP 4 编写的。新环境具有 PHP 5.2。
由于某种原因,应用程序在 PHP 5.2 中运行时会泄漏大量内存。我可以使用 memory_get_usage() 逐字地观察内存使用情况,直到达到 64 MB 的限制(这在共享环境中非常慷慨,该站点过去在 PHP 4 上以 12 或 16 MB 运行)。
我怀疑这是 PHP 5 中发生变化的副作用,很可能是参数中对象引用的处理。然而,搜索导致泄漏的特定行为极其困难,因为应用程序非常复杂,并且部分编写得不太好(是的,这是我的)。
由于该应用程序安装在共享网络空间上,因此我无法使用经典的调试工具(据我所知)。我非常非常希望避免在本地重新创建环境,因为我一整天都在为该项目工作一段时间。
所以我的问题是:
有人知道典型的 PHP4 => 吗? 5 个转换陷阱,特别是在处理大量对象时,这可能是我的泄漏的原因
有人知道某种独立于调试器、仅脚本的“图形范围转储”工具用于所使用的变量PHP 可能会帮助我找出哪些变量正在占用如此大量的内存?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了解决这个问题,我会:
这样做,您将能够:
对象模型从 PHP4 完全改变到 PHP5。当然,STRICT 模式会告诉您不应使用显式的“通过引用传递”。
To solve this issue I would:
Doing that, you will be able to:
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".
我在 5.2 的一个版本中发现的一个常见问题是 strtotime 泄漏而没有 memory_get_usage 捕获它。更改为 strptime 解决了该问题。
5.2.8 有一个错误报告 - http://bugs.php。 net/bug.php?id=46889。
One common one I found in one release of 5.2 was that strtotime leaked without memory_get_usage catching it. Changing to strptime fixed the issue.
There is a bug report for this for 5.2.8 - http://bugs.php.net/bug.php?id=46889.
如果没有调试器,您可以打开一个您认为使用大量内存的脚本,并将 memory_get_usage 函数放入关键局部变量中。
Without debugger you can open a script that you think use many memory and put memory_get_usage function in critical locals.