I've been trying to see a way to get a measure of how much a PHP script costs of memory to the server. Well, I've found some solutions out there that requires some software to make tests and even require to install something on the server. Those solutions are not what I'm looking for, as I just want a simple measure of the consumption.
My try was to do the following:
<?php $initialMem = memory_get_usage(); /* Script comes here */ $finalMem = memory_get_usage(); echo ($finalMem - $initialMem)/1024 . " Kbytes"; ?>
Where I divided by 1024 to convert from bytes to kilobytes. The idea was that the function memory_get_usage() gets the amount of memory allocated for the execution of the script and so I thought that taking the difference would be a good measure of the usage.
Is this correct? Is the difference between those values a good measure of the usage of memory by the script? If not, how can I get a good measure of this usage without having to install anything on the server?