在mod_php,并且调试内存使用情况 [英] Debugging memory usage in mod_php

查看:117
本文介绍了在mod_php,并且调试内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阿帕奇/ mod_php的运行请求处理程序偶尔膨胀超出最大允许内存使用量(即在php.ini中的memory_limit的定义)。

处理此请求调用proc_open()来运行外部命令。计数反对的要求内存使用情况?

这些命令的内存使用情况

除此之外,什么是preferred的方式来分析和修复下mod_php的运行脚本的内存使用情况?所有我身边的PHP内存使用中的信息似乎是:


  • 编辑php.ini并提高内存限制!

  • 编辑Apache的配置,并设置每个孩子最多的请求到一个较低的数字!

显然上述任一会对性能和稳定性产生负面影响。我怎么能进行实际的分析和解决问题,而不是创可贴吗?

Apache日志错误为:


  

PHP致命错误:允许内存大小
  用尽X字节(试着
  在线Z

foo.php分配ÿ个字节)

解决方案

我问关于PHP的内存管理一个类似的问题:<一href=\"http://stackoverflow.com/questions/849549/detecting-memory-leaks-in-large-php-stacks\">http://stackoverflow.com/questions/849549/detecting-memory-leaks-in-large-php-stacks

我相当肯定,从运行的exec()或proc_open()不计入PHP的内存限制。外部程序

在PHP跟踪内存使用显然是非常困难的。似乎没有成为一个方式来查找一个符号表之类的东西。

PHP有一对夫妇的内存管理功能,如 memory_get_usage() memory_get_peak_usage() 时,可以取的存储器在脚本任何给定的点所使用的总量。您的可能的编写自己的跟踪脚本,并将其放置,特设的,在关键点查找内存hoggers。

根据您的code-堆有多大,Xdebug的的执行跟踪可能你最好的选择。但是,这可能是矫枉过正,如果你有很多code的。

I have a request handler running in apache/mod_php which occasionally expands beyond the maximum allowed memory usage (ie, the memory_limit definition in in php.ini).

Handling this request calls proc_open() to run external commands. Is the memory usage of those commands counted "against" the requests memory usage?

Beyond that, what are the preferred ways to analyze and fix memory usage of scripts running under mod_php? All the information I've found around php memory usage seems to be:

  • "Edit php.ini and raise the memory limit!"
  • "Edit your apache config and set max requests per child to a lower number!"

Obviously either of these can have a negative effect on performance and stability. How can I actually analyze and fix the problem, rather than band-aid it?

Apache logs the error as:

PHP Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in foo.php on line Z

解决方案

I asked a similar question on PHP's memory management: http://stackoverflow.com/questions/849549/detecting-memory-leaks-in-large-php-stacks

I'm fairly certain that running external programs from exec() or proc_open() does NOT count against php's memory limit.

Tracking memory usage in PHP is apparently very difficult. There doesn't appear to be a way to look up a symbol table or anything like that.

PHP has a couple memory management functions, like memory_get_usage() and memory_get_peak_usage(), that can fetch the total amount of memory used at any given point in your script. You could write your own tracking script and place it, ad-hoc, at key points to find memory hoggers.

Depending on how large your code-stack is, xdebug's execution trace may be your best bet. But this can be overkill if you have lots of code.

这篇关于在mod_php,并且调试内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆