If you want to know how much memory PHP script uses, then in this case in PHP there is a great in-built function that is memory_get_usage().
memory_get_usage() — Returns the amount of memory allocated to PHP
int memory_get_usage ([ bool $real_usage = false ] )
Returns the amount of memory, in bytes, that’s currently being allocated to your PHP script.
Set this to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is reported.
Return Values :
Returns the memory amount in bytes.
<?php // Displays the amount of memory being used as soon as the script runs echo memory_get_usage() . "<br/>"; // Returns 46552 Bytes //Your code goes here $a = str_repeat('Avinash Pawar', 10000); // Displays the amount of memory being used by your code echo memory_get_usage() . "<br/>"; // Returns 176636 Bytes ?>