实践出 php 内存极限占用是多少.-PHP 源码
- <?php
- set_time_limit(0);
- echo 'memory_limit:'. $memory = ini_get('memory_limit').'
- ';
- $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.'
- ';
- echo '\$data string size:'. sprintf('%01.2f',strlen($data) / 1024 / 1024) .'MB';
- echo 'run memory:'. sprintf('%01.2f',(memory_get_usage() - $runtime) / 1024 / 1024) .'MB';
- exit();
来源: https://www.php1.cn/detail/php-ce300a2b12.html