Usually memory is not a problem for loading a web page, but in certain circumstances we will run out of memory. One of the first answers to resolve the problem is to allow our scripts to use more memory:
That's the easy way to solve our PHP memory problems but it is really a band aid solution. What we really want to do is find out why our script is using too much memory.
echo round(memory_get_usage() / 1048576, 2) . 'mb';
By echoing the value from the above function, we can see exactly how much memory our script is using at the time of the echo statement.
If you're making function or method calls that perform extensive computations then finding out how much memory each call is using is very important. Using memory_get_usage is a great way to find out how your scripts are performing.