生产服务器上的 PHP 内存峰值
我有 2 台服务器:本地服务器和远程生产服务器。它们的配置基本相同:Ubuntu 10.10、Apache 2、PHP 5.3、PHP-APC、MYsql 等。我还在两台服务器上都有 Web 应用程序的副本,这就是 PHP 的问题:
在我的本地服务器上,Web 应用程序仅使用 ~ 4 MB 内存,但在我的生产服务器上,内存使用量无缘无故地飙升至 50 MB 内存。我尝试运行 memory_get_peak_usage() 函数来获取 webapp 执行的不同阶段的内存使用情况,我发现在生产服务器上,在诸如 class_exists() 之类的函数调用中,内存峰值从 0.7 MB 上升到 49 MB。
可能是什么问题?
坦克。
I've got 2 servers: my local server and remote production server. They've got basically the same config: Ubuntu 10.10, Apache 2, PHP 5.3, PHP-APC, MYsql etc. I also have copies of a webapp on both servers and here's the problem with PHP:
On my local server webapp uses only ~4 MB of memory, but on my production server memory usage spikes up to 50 MB of memory for no good reason. I tried to run memory_get_peak_usage() function to get memory usage at different stages of webapp execution and i've found that on production server memory spikes from 0.7 up to 49 MB on such function calls as class_exists().
What could be the problem?
Tanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不想听起来很无聊,但是您是否已验证它们具有完全相同的 Apache/PHP 配置,因为它们很容易成为此类差异的根源。
它们是否也经历相同类型的负载,因为在负载下的服务器上运行的代码与在充足的无竞争资源下运行的代码的行为可能非常不同。
其他正在运行的应用程序是否存在可能影响内容的其他差异?
也许值得对两台服务器上的代码进行分析,看看是否存在任何每个请求的差异,XHprof[1] 是一个很好的工具,它可以安全地在生产中运行(只要您阅读说明)
[1 ] http://phpadvent.org/2010/profiling-with-xhgui-by-paul-reinheimer
Hate to sound a bore, but have you verified that they have exactly the same Apache/PHP config as they can easily become the source of these sort of differences..
Also are they experiencing the same sort of load, as code running on a server under load can behave very differently to code running with ample uncontested resources.
Are there any other differences in terms of other running applications that could be affecting stuff?
It maybe worth profiling the code on both the servers to see if there are any per-request differences, XHprof[1] is a great tool for this and it can safely be run in production (as long as you read the instructions)
[1] http://phpadvent.org/2010/profiling-with-xhgui-by-paul-reinheimer
好的,我已经找到问题所在了。有一个类正在创建包含用户浏览器信息的缓存文件(以便稍后识别它们)。显然该文件和/或解析器存在问题,因此它使用了太多内存。从那时起,我已经清除了缓存文件,如果情况再次发生,我将完全放弃该类。
感谢所有回答/评论问题的人。
Ok, i've found where was a problem. There is a class that was creating cache file containing information on user's browser (in order to recognize them later). Apparently there was a problem with that file and/or parser so it was using too much memory. Since then i've cleared cache files and if situation will repeat, i'll ditch that class altogether.
Thanks to all who answered/commented on problem.