在格式化memory_get_usage()输出

代码如下复制代码

$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));
?>

输出:256 kb

代码如下复制代码

if (!function_exists('memory_get_usage'))

{
function memory_get_usage()

{

$pid = getmypid();

if (IS_WIN)

{

exec('tasklist /FI "PID eq ' . $pid . '" /FO LIST', $output);

return preg_replace('/[^0-9]/', '', $output[5]) * 1024;

}

else

{

exec("ps -eo%mem,rss,pid | grep $pid", $output);

$output = explode(" ", $output[0]);

return $output[1] * 1024;

}

}

}

08-29 00:26