[英]how can i find out where all my memory has gone in PHP?
i have a script that does a lot of processing on some rows from the DB(lots of them). 我有一个脚本,对DB中的一些行(很多行)进行了大量处理。 The script is using lots of objects, and some internal caching mechanisms.
该脚本使用了大量对象和一些内部缓存机制。
At some point, i'm freeing all used cache, to avoid eating all the available RAM just for the cached items, but the used memory isn't decreasing. 在某些时候,我释放所有使用过的缓存,以避免仅为缓存的项目吃掉所有可用的RAM,但使用的内存不会减少。
I've used memory_get_usage(true)
to determine how much RAM the script is taking, but i have no ideea how to detect what objects are still in RAM and still eating up memory. 我已经使用
memory_get_usage(true)
来确定脚本占用了多少RAM,但是我没有想法如何检测哪些对象仍然在RAM中并仍然占用内存。
The simple solution is to go back through all objects, and make sure no variables are still alive and pointing at them, and that all internal caches are actually free'd and test and test and test again, but I'm looking for a tool or a function call that would tell me that "variable Y in class Z has 90% of your RAM", without having to know and mess with all the internals of the objects that i use in this script. 简单的解决方案是返回所有对象,并确保没有变量仍然存在并指向它们,并且所有内部缓存实际上都是免费的并且再次测试和测试并测试,但我正在寻找一个工具或者一个函数调用会告诉我“Z类中的变量Y有90%的RAM”,而不必知道并弄乱我在这个脚本中使用的所有对象的内部。
Why don't you profile your script? 你为什么不描述你的脚本?
Use xdebug with the profiler turned on and investigate what is going on at your cachegrind file. 在启用了分析器的情况下使用xdebug并调查cachegrind文件的内容。
See more here: http://www.xdebug.org/docs/profiler 在此处查看更多信息: http : //www.xdebug.org/docs/profiler
Update: You could get more memory related information by using xdebug.show_mem_delta parameter in conjunction with xdebug.trace_format both set to 1 to get memory usage in a simple html. 更新:您可以通过将xdebug.show_mem_delta参数与xdebug.trace_format一起设置为1来获取更多与内存相关的信息,以便在简单的html中获取内存使用情况。
Check this http://xdebug.org/docs/execution_trace and this http://derickrethans.nl/xdebug-and-tracing-memory-usage.html to get some ideas. 请查看此http://xdebug.org/docs/execution_trace和此http://derickrethans.nl/xdebug-and-tracing-memory-usage.html以获取一些想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.