下面是使用示例:
复制代码 代码如下:
echo memory_get_usage(), '
'; // 313864
$tmp = str_repeat('http://www.nowamagic.net/', 4000);
echo memory_get_usage(), '
'; // 406048
unset($tmp);
echo memory_get_usage(); // 313952
?>
复制代码 代码如下:
if (!function_exists('memory_get_usage'))
{
/**
+----------------------------------------------------------
* 取得内存使用情况
+----------------------------------------------------------
* @return integer
+----------------------------------------------------------
*/
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;
}
}
}
复制代码 代码如下:
//memory_get_usage();
$m1 = memory_get_usage();
echo '
m1:',$m1;//58096
$a = 'hello';
$b = str_repeat($a,1000);
$m2 = memory_get_usage();
echo '
m2:',$m2;//63424
unset($b);
$m3 = memory_get_usage();
echo '
m3:',$m3;//58456
?>