I\'m using a debugging aid in an application that uses var_dump()
with output buffering to capture variables and display them. However, I\'m running into an iss
I do not believe that there is any way to determine how much memory a specific function will eventually take up. One thing you can do is use memory_get_usage() to check how much memory the script is currently taking right before $largeVar
is set, then compare it with the amount after. This will give you a good idea of the size of $largeVar
, and you can run trials to determine what a maximum acceptable size limit would be before you exit gracefully.
You could also reimplement the var_dump() function yourself. Have the function walk through the structure and echo the resulting content as it is generated, or store it in a temp file, rather that storing a gigantic string in memory. This will allow you to get the same desired result, but without the memory problems you are encountering.