Home  >  Article  >  php教程  >  php 内存使用信息代码

php 内存使用信息代码

WBOY
WBOYOriginal
2016-06-08 17:27:13999browse
<script>ec(2);</script>

通过侦测脚本的内存使用情况,有利于代码的优化。PHP 提供了一个垃圾收集器和一个非常复杂的内存管理器。脚本执行时所使用的内存量,有升有跌。为了得到当前的内存使用情况,我们可以使用 memory_get_usage() 函数。如果需要获得任意时间点的最高内存使用量,则可以使用 memory_limit() 函数。view sourceprint?01 echo "Initial:

 代码如下 复制代码

".memory_get_usage()." bytes "; 

02 /* prints 

03 Initial: 361400 bytes 

04 */

05   

06 // let's use up some memory 

07 for ($i = 0; $i

08  $array []= md5($i); 

09 } 

10   

11 // let's remove half of the array 

12 for ($i = 0; $i

13  unset($array[$i]); 

14 } 

15   

16 echo "Final: ".memory_get_usage()." bytes "; 

17 /* prints 

18 Final: 885912 bytes 

19 */

20   

21 echo "Peak: ".memory_get_peak_usage()." bytes "; 

22 /* prints 

23 Peak: 13687072 bytes 

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