PHP extension

Lifecycles

PHP Architecture

PHP Architecture

PHP的启动与终止

MINIT

MINIT全称Module Initialization,是由每个扩展自己实现的一个函数

PHP_MINIT_FUNCTION

RINIT

Request Initialization

PHP_RINIT_FUNCTION

RSHUTDOWN

Request Shutdown

PHP_RSHUTDOWN_FUNCTION

MSHUTDOWN

Module Shutdown

PHP_MSHUTDOWN_FUNCTION

VAR

zval

struct _zval_struct {
zvalue_value value; /* 变量的值 */
zend_uint refcount__gc;
zend_uchar type; /* 变量当前的数据类型 */
zend_uchar is_ref__gc;
};
typedef struct _zval_struct zval;

typedef unsigned int zend_uint;
typedef unsigned char zend_uchar;

typedef union _zvalue_value {
long lval; /* long value */
double dval; /* double value */
struct {
char *val;
int len;
} str;
HashTable *ht; /* hash table value */
zend_object_value obj;
} zvalue_value;

8种数据类型

IS_NULL

null

IS_BOOL

true; false

IS_LONG

signed long

IS_DOUBLE

signed double

IS_STRING

IS_ARRAY

HashTable

IS_OBJECT

IS_RESOURCE

#define Z_TYPE(zval) (zval).type
#define Z_TYPE_P(zval_p) Z_TYPE(*zval_p)
#define Z_TYPE_PP(zval_pp) Z_TYPE(**zval_pp)

...

创建PHP变量

ZVAL_NULL(pvz);

ZVAL_BOOL(pzv, b);

...

ZVAL_STRINGL(pzv,str,len,dup);

ZVAL_STRING(pzv, str, dup);

MM

C: malloc、free、strdup、realloc、calloc

引用计数

Hello World!

Array与HashTable

Zend

HashTable

Data structure

Data structure

a