memory_get_usage

Is My PHP Script Running Out Of Memory?

I’ve got a PHP script that sometimes just dies with no errors to the browser and no messages in the error log. I’ve seen this in the past with scripts that consumed too much memory (yeah, it should have issued an error, but it didn’t, and increasing the memory limit fixed it), but now the memory limit is set pretty high and I’m not sure I want to increase it further. I certainly don’t want to increase it without seeing where it’s going wrong, anyway.

To do that, IBM developerWorks says the memory_get_usage() and memory_get_peak_usage() functions are for me. And they offer some other interesting tips as well.