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 释放全局变量时

最新文章

  1. 动态生成一个设定好特殊样式的Tlabel,快速生成代码
  2. addLoadEvent方法解析
  3. Xamarin.Forms入门学习路线
  4. [NOIP2011] 提高组 洛谷P1311 选择客栈
  5. poj 1797(最短路变形)
  6. Winform-控制边框显示属性
  7. bzoj题解
  8. [008]new、delete及动态内存分配
  9. easyui plugin —— etreegrid:CRUD Treegrid
  10. android 反纠结app开发: 在线程中更新view
  11. Java 编程的动态性,第 8 部分: 用代码生成取代反射--转载
  12. Qt之四方分割器QuadSplitter
  13. jQuery圆形统计图实战开发
  14. 记录Window系统下myeclipes连接linux下mysql所出现的一个bug
  15. C# WinForm:无法访问已释放的对象
  16. restful 跨域
  17. day 06 编码and知识点总结
  18. 支付宝(查询对账单下载地址(alipay.data.dataservice.bill.downloadurl.query))
  19. Python argparse 模块
  20. 转载:移动端+微信小程序实现,手机端滑动分页代码思路(ajax)

热门文章

  1. mongodb 只查询一个字段
  2. @JVM新一代的垃圾回收算法
  3. Linq编程小趣味爱因斯坦谜题
  4. ajax与java前后台传值及数据表查询解决一个bug的问题
  5. 全局 Style
  6. 在Linux上安装Chef工作站
  7. Transformer中引用iqd作为数据源的时候数据预览出现乱码
  8. GBDT(Gradient Boost Decision Tree)
  9. 在Fedora8上安装使用ActiveMQ5.8
  10. C++:cin、cin.getline()、getline()的用法