1、下载php7.1。http://us1.php.net/downloads.php#v7.1.20
2、进入源码目录的ext目录.
3、执行./ext_skel –extname=helloword
生成扩展骨架
3、修改config.m4
文件,该文件中的dnl
代表注释,将以下代码前的dnl去掉:
dnl PHP_ARG_WITH(helloworld, for helloworld support,
dnl Make sure that the comment is aligned:
dnl [ --with-helloworld Include helloworld support])
dnl Otherwise use enable:
dnl PHP_ARG_ENABLE(helloworld, whether to enable helloworld support,
dnl Make sure that the comment is aligned:
dnl [ --enable-helloworld Enable helloworld support])
4、在helloworld.c中找到如下代码:
PHP_FUNCTION(confirm_helloworld_compiled)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
return;
}
strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "helloworld", arg);
RETURN_STR(strg);
}
在改代码后面加一个
PHP_FUNCTION(helloWorld);
5、找到如下代码:
const zend_function_entry helloworld_functions[] = {
PHP_FE(confirm_helloworld_compiled, NULL) /* For testing, remove later. */
PHP_FE(helloWorld, NULL) //添加这一行注册自定义函数
PHP_FE_END /* Must be the last line in helloworld_functions[] */
};
6、在helloworld.c文件末尾添加helloworld函数的代码实现:
PHP_FUNCTION(helloWorld)
{
php_printf("Hello World!\n");
RETURN_TRUE;
}
7、回到源码目录编译安装:
phpize
./configure(如果想指定php文件配置的话:./configure --with-php-config=/usr/bin/php-config7.1 ,不同的Linux版本位置可能不同)
make
sudo make install
附两篇参考文档:
https://blog.csdn.net/u011957758/article/details/72456298
网友评论