易截截图软件、单文件、免安装、纯绿色、仅160KB

php variable circular reference

 
Php Variable Circular References

Circular-references has been a long outstanding issue with PHP. They are
caused by the fact that PHP uses a reference counted memory allocation
mechanism for its internal variables. This causes problems for longer
running scripts (such as an Application Server
or
the eZ Components
test-suite) as the memory is not freed until the end of the request. But
not everybody is aware on what exactly the problem is, so here is a
small introduction to circular references in PHP.

In PHP a refcount value is kept for every variable container (zval).
Those containers are pointed to from a function's symbol table that
contains the names of all the variables in the function's scope. Every
variable, array element or object property that points to a zval will
increase its refcount by one. The refcount of a zval container is
decreased by one whenever call unset() on a variable name that points to
it, or when a variable goes away because the function in which it was
used ends. For a more thorough explanation about references, please see
the article on this
that I
wrote for php|architect
some time
ago.

The problems with circular references all start by creating an array or
an object:

<?php
$tree = array( 'one' );
?>
This creates the following structure in memory:


Now if we proceed to add a new element to the array, that points back to
the array with:

<?php
$tree[] = $tree;
?>
We create a circular reference like this:


As you can see there are two variable names pointing to the array
itself. Once through the $tree variable, and once through the 2nd
element of the array. Because there are two variable names pointing to
the container, its refcount is 2.

Now, the next step that actually creates the problem if we unset() the
$tree variable. As I mentioned before an unset() on a variable name will
decrease the refcount of the variable container the variable poi


相关文档:

php 时间戳

PHP时间大的来分有两种,一是时间戳类型(1228348800),二是正常日期格式(2008-12-4)
所以存到数据库也有两种形式了(真正不止,我的应用就两种),时间戳类型我是保存为字符串的,这个是比较方便的.
正常日期类型是保存为DATE型的.
这两个要注意一下,我平时用两种,所以,前几天建的表,把时间类型存为DATE的,我还一直用时间戳保存 ......

关于php面向对象的静态变量的问题


代码如下:
<?php
class Book{
    static $num=0;
    public function showme(){
        echo '您是第'.self::$num.'位访客';
        self::$num++;
     ......

php常用类整理

在实际开发过程会经常会遇到一些重复的操作,如果每次都要自己去实现这无疑加重了自己的工作量,下面对一些可能经常用到的类做个整理:
图表库
下面的类库可以让你很简单就能创建复杂的图表和图片。当然,它们需要GD库的支持。
pChart - 一个可以创建统计图的库。
Libchart - 这也是一个简单的统计图库。
JpGraph - 一 ......

php配置文件详解

[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The follo ......

使用linux共享内存的实现的php内存队列

<?php
/**
* 使用共享内存的PHP循环内存队列实现
* 支持多进程, 支持各种数据类型的存储
* 注: 完成入队或出队操作,尽快使用unset(), 以释放临界区
*
* @author wangbinandi@gmail.com
* @created 2009-12-23
*/
class SHMQueue
{
private $maxQSize = 0; // 队列最大长度

private $front = 0; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号