How can I find out where all my memory went in PHP?

I have a script that does a lot of processing some lines from the DB (many of them). The script uses a lot of objects and some internal caching mechanisms.

At some point, I release all used cache so that I don't have all the available RAM just for cached items, but the used memory does not decrease.

I used memory_get_usage(true)

to determine how much RAM a script is taking up, but I don't know how to determine which objects are still in RAM and there is still memory.

A simple solution is to go back to all objects and make sure the variables are still not alive and not pointing to them, and that all internal caches are actually free, and then check and test and test again, but I'm looking for a tool or function call that would tell me that "the variable Y in class Z has 90% of your RAM" without knowing or interfering with all the internal objects of the objects that I use in this script.

+3


source to share


1 answer


Why don't you profile your script?

Use xdebug with profiler enabled and investigate what's going on in your cachegrind file.

More details here: http://www.xdebug.org/docs/profiler



Update. You can get more information related to memory by using the xdebug.show_mem_delta parameter in combination with xdebug.trace_format set to 1 to get the memory usage in plain html.

Check http://xdebug.org/docs/execution_trace and http://derickrethans.nl/xdebug-and-tracing-memory-usage.html for some ideas.

+2


source







All Articles