我不熟悉c, 也不熟悉php, 所以为了能实现用c写php module的功能, 着实还是费了点儿周折。
在php源代码包中,已经包含了生成php module的脚本配置方案, 按照下列步骤即可:
当前目录: /*/*/php-*/ext
1. ./ext_skel extname="hello"
生成名为 “hello”的模块
并生成3个模板文件: hello.c hello.php php_hello.h
2. cd hello
vim config.m4
删除以下语句的注释
PHP_ARG_ENABLE(hello, whether to enable hello support,
Make sure that the comment is aligned:
[ --enable-hello Enable hello support])
注意此处不能使用 --with参数
3. phpize
为此模块生成配置文件
4. ./configure
5. make
在modules中生成hello.la hello.so两个文件
6. make test
7. make install
将hello.so文件cp到$PHP_HOME/lib/php/extensions/no-debug-non-zts-*/
10. php -f hello.php
返回结果如下:
Functions available in the test extension:
confirm_hello_compiled
Congratulations! You have successfully modified ext/hello/config.m4. Module hello is now compiled into PHP.
11.编译成功。
剩下的工作就是修改 hello.c hello.php php_hello.h, 实现自己的功能需求,并重复执行5-10.
在web中调用hello.so, 还需要以下2步:
1. 在php.ini中设置so加载项
extension=hello.so
2. 重新启动php
在php源代码包中,已经包含了生成php module的脚本配置方案, 按照下列步骤即可:
当前目录: /*/*/php-*/ext
1. ./ext_skel extname="hello"
生成名为 “hello”的模块
并生成3个模板文件: hello.c hello.php php_hello.h
2. cd hello
vim config.m4
删除以下语句的注释
PHP_ARG_ENABLE(hello, whether to enable hello support,
Make sure that the comment is aligned:
[ --enable-hello Enable hello support])
注意此处不能使用 --with参数
3. phpize
为此模块生成配置文件
4. ./configure
5. make
在modules中生成hello.la hello.so两个文件
6. make test
7. make install
将hello.so文件cp到$PHP_HOME/lib/php/extensions/no-debug-non-zts-*/
10. php -f hello.php
返回结果如下:
Functions available in the test extension:
confirm_hello_compiled
Congratulations! You have successfully modified ext/hello/config.m4. Module hello is now compiled into PHP.
11.编译成功。
剩下的工作就是修改 hello.c hello.php php_hello.h, 实现自己的功能需求,并重复执行5-10.
在web中调用hello.so, 还需要以下2步:
1. 在php.ini中设置so加载项
extension=hello.so
2. 重新启动php