Home  >  Article  >  php教程  >  实践出php内存极限占用是多少.

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

PHP中文网
PHP中文网Original
2016-05-25 17:07:121015browse

<?php 
set_time_limit(0);

echo &#39;memory_limit:&#39;. $memory = ini_get(&#39;memory_limit&#39;).&#39;<br />&#39;;

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

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn