RSS
热门关键字:  QQ密码破解  最新的盗QQ的软件  江淮影视  网页密码破解  最后诊断
当前位置 :| 主页>web技术>php>

如何制作 php扩展 C 语言

来源: 作者: 时间:2007-12-11 Tag: 点击:
到PHP的安装目录下

[root@test1 ext]# cd /root/php/php5.2/ext

[root@test1 ext]# ./ext_skel --extname=cltest


修改 配置文件config.m4

[root@test1 ext]# vi cltest/config.m4  

删除 3 个 dnl

dnl PHP_ARG_WITH(my_module, for my_module support,

dnl Make sure that the comment is aligned:

dnl [ --with-my_module Include my_module support])


或者删除 下边这3个 dnl

dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,

dnl Make sure that the comment is aligned:

dnl [ --enable-my_module Enable my_module support])

修改完毕。


在my_module.c扩展模块的主程序文件中加PHP的函数定义

主程序中描述了php扩展模块的声明,模块中含有多少个函数,各个函数的作用,在phpinfo函数中显示什么内容,模块初始化做些什么,结束做些什么都会在这个文件里进行描述。我们在上面只是添加了一个函数say_hello,并且描述了say_hello函数的具体内容

[root@test1 ext]# Vi cltest.c


function_entry my_module_functions[] = {


PHP_FE(say_hello, NULL) /* ?添加这一行代码   注册函数say_hello() */

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

{NULL, NULL, NULL} /* Must be the last line in my_module_functions[] */

};

在文件的最后添加下列代码 函数程序主体

PHP_FUNCTION(say_hello)
{
       RETURN_STRINGL("hello world",100,1);
}

修改完毕。



在my_module.h扩展模块的头文件中加PHP启动时要注册的函数

在对应的头文件中声明了say_hello这个函数,从而完成了我们预期的功能。

[root@test1 ext]# vi php_cltest.h

在文件中PHP_FUNCTION(confirm_my_module_compiled);一行前面添加下面的代码 函数定义

PHP_FUNCTION(say_hello);


保存文件退出,修改完毕。
栏目列表