从 PHP 4 到 5 的过渡过程中出现内存泄漏 - 有什么提示吗?

发布于 2024-08-08 07:44:35 字数 570 浏览 2 评论 0原文

我正在将大型 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So要识趣 2024-08-15 07:44:35

为了解决这个问题,我会:

  1. 使用 xdebug+wincachegrind (或其他一些分析器)和/或 firephp 分析脚本。
  2. 打开 STRICT 模式以获取所有 php 错误 + 通知。

这样做,您将能够:

  • 优化您的代码。 (删除错误/警告/通知可以加快您的代码速度)
  • 清理您的代码。 (使用正确的 php5 对象语法只会有利于性能)。

对象模型从 PHP4 完全改变到 PHP5。当然,STRICT 模式会告诉您不应使用显式的“通过引用传递”。

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".

随梦而飞# 2024-08-15 07:44:35

我在 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.

倾城月光淡如水﹏ 2024-08-15 07:44:35

如果没有调试器,您可以打开一个您认为使用大量内存的脚本,并将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文