php内存控制

<?php
//memory_get_usage
/*
memory_get_usage:查看内存使用情况

memory_get_usage---Returns the amount of memory allocated to PHP

information:
int memory_get_usage([bool | $real_usage=false])

Returns the amount of memory ,in bytes ,that's currently being allocated to your PHP script.
返回内存量,以字节为单位,即当前被分配到你的PHP脚本.

real_usage
Set this to TRUE to get the real size of memory allocated from system.If not set or FALSE only the momory used by emalloc() is reported.
设置为TRUE,才能得到真正的从系统中分配的内存的大小,如果没有设置或FALSE,只有通过emalloc()使用的内存的报告.


返回:
Returns the memory amount in bytes


+-----------------------------------------------------------------------------------------+
深入理解PHP内存之谁动了我的内存???

首先我们看以下代码,会有以下输出:

var_dump(memory_get_usage()):
$a="laruence";
var_dump(memory_get_usage());
unset($a);
var_dump(memory_get_usage());

输出以下的代码
int(61176)
int(61360)
int(61264)

有人说unset会不会释放内存,那么这32个字节跑到了哪里去了??

这丢失的字节去那里了??
首先我们要打破一个思维,PHP不像C语言那样,只有你显示的调用内存分配相关的API才会有内存的分配.也就是在PHP里面,有很多我们看不到的内存分配过程

$a="laruence";

隐式的内存分配点就有:
1.为变量名分配内存,存入符号表
2.为变量值分配内存
所以不能直看表象

第二,别怀疑PHP的Unset确实会释放内存(当然还要结合引用和技术,这部分内容)

对PHP来说,他自身提供了一套和C语言对内存分配相似的内存管理API


emallaoc(size_t size);
efree(void  *ptr);
ecalloc(size_t nmeb,size_t size);
erealloc(void *ptr,size_t size);
estrdup(const char *s);
estrndup(const char *s, unsigned int length);
+-----------------------------------------------------------------------------------------+
zend_version
(PHP4,PHP5)
zend_version--Gets the version of the current Zend engine.

string zend_version(void)
Returns a string containing the version of the currently running Zend Engine.

返回值:
Returns the Zend Engine version number,as a string.

例如
<php echo zend_version();>


 

posted @ 2012-09-29 15:51  sgsheg  阅读(256)  评论(0编辑  收藏  举报