时间:2021-07-01 10:21:17 帮助过:10人阅读
输出:62328 122504 62416
echo memory_get_usage();
$var = str_repeat("liuhui", 10000);
echo memory_get_usage();
unset($var);
echo memory_get_usage();
?>
分别
输出:256 kb
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_usage(true));
?>
function array_size($arr) {
ob_start();
print_r($arr);
$mem = ob_get_contents();
ob_end_clean();
$mem = preg_replace("/\n +/", "", $mem);
$mem = strlen($mem);
return $mem;
}
$memEstimate = array_size($GLOBALS);
?>
参考资料:http://cn.php.com/manual/en/function.memory-get-usage.phphttp://www.bkjia.com/PHPjc/324682.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324682.htmlTechArticle一,函数原型 int memory_get_usage ([ bool $real_usage = false ] ) 二,版本兼容 PHP 4 = 4.3.2, PHP 5 三,基础用法与实例 1,获取当前的内存消耗量 复制代...