简体   繁体   English

我怎样才能找到我的所有内存在PHP中的位置?

[英]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.

相关问题 在netbeans和php中,如何找出某个函数/方法被调用的程序的所有文件/区域 - in netbeans and php, how can i find out all the files/areas of a program where a certain function/method is called 如何自动提醒我的php / mysql网络应用程序PayPal交易已通过? - How can I automatically alert my php/mysql web app that a PayPal transaction has gone through? 我怎样才能知道我的 output 是从哪里开始的? - How can I find out where my output started? 如何找出路由在php中的参数 - How can I find out which parameters a route has in php 如何确定我的用户是否具有管理员权限? - How can I find out if my user has an admin permission? mysqli_query返回null,找不到我哪里出错了。 PHP-MySQL - mysqli_query returning null, can't find where I have gone wrong. PHP - MySQL 如何查找PHP应用程序中调用过函数的次数和位置? - How can I find how many times, and where, a function has been called in a PHP application? PHP在我的所有脚本中耗尽内存 - PHP running out of memory in all my scripts 如何判断我的内存是否已被PHP应用程序安全释放? - How can I tell if my memory has been released securely by a PHP application? 我如何找出所有可能由一段PHP代码抛出的错误? - How can I find out all the errors that can possibly be thrown by a block of PHP code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM