- <?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();
- //该片段来自于http://www.codesnippet.cn/detail/171020136466.html
来源: http://www.codesnippet.cn/detail/171020136466.html