在PHP中,新
发现一个可以简单监视
内存使用情况的pecl叫
memtrack(地址:http://php.net/manual/en/book.memtrack.php)
安装:pecl install memtrack
简单设置下:
extension=memtrack.so
memtrack.enabled = 1 ; enabling Memtrack extension
memtrack.soft_limit = int ; set memory limit for
functions
更多设置见(http://www.php.net/manual/en/memtrack.ini.php)
使用
例子:
extension=memtrack.so
memtrack.enabled = 1
memtrack.soft_limit = 1M
一个程序:
<?php
function foo() {
$a = array();
for ($i = 0; $i < 10000; $i++) $a[] = "test";
return $a;
}
$arr = foo();
?>
命令行下运行:
php -d memtrack.enabled=1 -d memtrack.soft_limit=1M -d memtrack.vm_limit=3M /tmp/example1.php
输出:
Warning: [memtrack] [pid 26177] user function foo() executed in /tmp/example1.php on line 10 allocated 4194304 bytes in /tmp/example1.php on line 0
Warning: [memtrack] [pid 26177] virtual memory usage on shutdown: 32911360 bytes in Unknown on line 0
当然,这东西还比较简单,不过可以简单用一下