Php版本:7.0.0

首先进入php源码 ext 目录下

执行./ext_skel --extname=foobar //foobar为我要创建的扩展模块

执行完毕后

cd ext/foobar/

vim config.m4

16 dnl PHP_ARG_ENABLE(foobar, whether to enable foobar support,

17 dnl Make sure that the comment is aligned:

18 dn1 [ --enable-foobar Enable foobar support])

把16、17、18行的dn1去掉,修改为

16 PHP_ARG_ENABLE(foobar, whether to enable foobar support,

17 Make sure that the comment is aligned:

18 [ --enable-foobar Enable foobar support])

然后 vim foobar.c

找到

PHP_FUNCTION(confirm_foobar_compiled)

{

..............

}

在后面添加

PHP_FUNCTION(flyhello)

{

zend_string *strg;

strg = strpprintf(0, "hello world.");

RETURN_STR(strg);

}

然后找到

const zend_function_entry foobar_functions[] = {

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

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

};

修改为

const zend_function_entry foobar_functions[] = {

 PHP_FE(flyhello,NULL)

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

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

};

然后重新编译执行后,执行php -m 就可以看到foobar模块

新建php文件,内容<?Php echo flyhello();?> 执行后输出hello world.