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

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

PHP中文网
Release: 2016-05-25 17:07:12
Original
1074 people have browsed it

<?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();
Copy after login

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template