Linux下用C开发PHP扩展
1:找到源代码路径
可以直接搜索:find / -name ext_skel
2:编写一个函数定义文件,该文件编写函数原型后缀为def,假设为:zy_module.def
3:通过扩展骨架生成器,将在ext目录下自动建立扩展目录zy_module
./ext_skel --extname=zy_module --proto=zy_module.def
4:修改配置文件:#> vim zy_module/config.m4,将如下行的注释标签"dnl"去掉,修改后如下所示:
PHP_ARG_ENABLE(myfunctions,whether to enable myfunctions support,
Makesure that the comment is aligned:
[ --enable-myfunctions Enablemyfunctions support])
5:完善函数zya和zyb的功能: #>vim ext/zy_module/zy_module.c
6:
Cd ext/zy_module下
生成可编译的文件
7:Make && makeinstall
生成的 so扩展库的路径
8:php.ini 中 加入该扩站 重启php
9:实例调用:
第一个函数计算两个数之和
第二个函数重复字符串的次数
打印出来:
1:3
2:ceshiceshiceshiceshiceshi