Thứ Hai, 19 tháng 5, 2014

Check how much memory your PHP script is using

Check how much memory your PHP script is using?


The answer is the memory_get_peak_usage() function.

At the end of your PHP script (footer script for a PHP site, you get the idea), put this line:
echo memory_get_peak_usage();
Or you can write the data down in a text file:
file_put_contents('mu.txt', memory_get_peak_usage());
The output is in bytes.More friendly output,Add to the footer of the templates:
<?php
function convert($size) {
   $unit=array('b','kb','mb','gb','tb','pb');
   return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
echo convert(memory_get_peak_usage(true));
?>

Share This!


Không có nhận xét nào:

Đăng nhận xét