php 基本结构,PHP扩展的基本结构

1、下载php源码

git clone https://github.com/php/php-src.git

2,创建扩展

cd php-src/ext/

./ext_skel --extname=php_hello

3、修改config.m4

PHP_ARG_ENABLE(php_hello, whether to enable php_hello support,

Make sure that the comment is aligned:

[ --enable-php_hello Enable php_hello support])

if test "$PHP_PHP_HELLO" != "no"; then

PHP_NEW_EXTENSION(php_hello, php_hello.c, $ext_shared)

fi

这样一个基本的扩展就好了

4、Zend函数块入口

vim ./zend_API.h +35

typedef struct _zend_function_entry {

const char *fname;

void (*handler)(INTERNAL_FUNCTION_PARAMETERS);

const struct _zend_arg_info *arg_info;

zend_uint num_args;

zend_uint flags;

} zend_function_entry;

fname 函数名

handler 处理接口函数的指针

_zend_arg_info 函数参数

const zend_function_entry hello_functions[] = {

PHP_FE(confirm_hello_compiled, NULL) /* For testing, remove later. */

PHP_FE_END /* Must be the last line in hello_functions[] */

};

5、Zend模块扩展结构

typedef struct _zend_module_entry zend_module_entry;

struct _zend_module_entry {

unsigned short size;

unsigned int zend_api;

unsigned char zend_debug;

unsigned char zts;

const struct _zend_ini_entry *ini_entry;

const struct _zend_module_dep *deps;

const char *name;

const struct _zend_function_entry *functions;

int (*module_startup_func)(INIT_FUNC_ARGS);

int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);

int (*request_startup_func)(INIT_FUNC_ARGS);

int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS);

void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS);

const char *version;

size_t globals_size;

#ifdef ZTS

ts_rsrc_id* globals_id_ptr;

#else

void* globals_ptr;

#endif

void (*globals_ctor)(void *global TSRMLS_DC);

void (*globals_dtor)(void *global TSRMLS_DC);

int (*post_deactivate_func)(void);

int module_started;

unsigned char type;

void *handle;

int module_number;

const char *build_id;

};

扩展中

/* {{{ hello_module_entry

*/

zend_module_entry hello_module_entry = {

#if ZEND_MODULE_API_NO >= 20010901

STANDARD_MODULE_HEADER,

#endif

"hello",

hello_functions,

PHP_MINIT(hello),

PHP_MSHUTDOWN(hello),

PHP_RINIT(hello), /* Replace with NULL if there‘s nothing to do at request start */

PHP_RSHUTDOWN(hello), /* Replace with NULL if there‘s nothing to do at request end */

PHP_MINFO(hello),

#if ZEND_MODULE_API_NO >= 20010901

PHP_HELLO_VERSION,

#endif

STANDARD_MODULE_PROPERTIES

};

/* }}} */

6、运行过程

#define PHP_MINIT_FUNCTION ZEND_MODULE_STARTUP_D

#define PHP_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D

#define PHP_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D

#define PHP_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D

#define PHP_MINFO_FUNCTION ZEND_MODULE_INFO_D

#define PHP_GINIT_FUNCTION ZEND_GINIT_FUNCTION

#define PHP_GSHUTDOWN_FUNCTION ZEND_GSHUTDOWN_FUNCTION

#define PHP_MODULE_GLOBALS ZEND_MODULE_GLOBALS

解释

PHP_MINIT_FUNCTION 初始化module时运行

PHP_MSHUTDOWN_FUNCTION 当module被卸载时运行

PHP_RINIT_FUNCTION 当一个REQUEST请求初始化时运行

PHP_RSHUTDOWN_FUNCTION 当一个REQUEST请求结束时运行

PHP_MINFO_FUNCTION 这个是设置phpinfo中这个模块的信息

PHP_GINIT_FUNCTION 初始化全局变量时

PHP_GSHUTDOWN_FUNCTION 释放全局变量时

原文:http://www.cnblogs.com/chenpingzhao/p/4706158.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值