欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

实践出php内存极限占用是多少.

程序员文章站 2022-05-11 20:52:15
...
<?php 
set_time_limit(0);

echo 'memory_limit:'. $memory = ini_get('memory_limit').'<br />';

$string = 'abcde';  // 运行字符串, 可修改这儿.
$memory =($memory+0)*1024*1024;
$runtime = memory_get_usage();
$runcount = $memory / (strlen($string)+1); // 为什么+1? 因为需要留点内存给其它变量或者计算式.
$i = 0;

while($i < $runcount){
    $i ++;
    $data .= $string;
}

echo 'all run count: '.$i.'<br />';
echo '\$data string size:'. sprintf('%01.2f',strlen($data) / 1024 / 1024) .'MB <br />';
echo 'run memory: '. sprintf('%01.2f',(memory_get_usage() - $runtime) / 1024 / 1024) .'MB';
exit();