编译php扩展,编译php扩展

1) ext_skel

JesusSlimsMBFuxkingP:php5.6.6 jesusslim$ cd /Applications/MAMP/bin/php/php5.6.6/include/php

JesusSlimsMBFuxkingP:php jesusslim$ cd ext

JesusSlimsMBFuxkingP:ext jesusslim$ ./ext_skel --extname=hello_module

0818b9ca8b590ca3270a3433284dd417.png

在这个目录下生成一个目录叫hello_module

进入

然后我们要修改文件顺序是

configue.m4

hello_module.c

php_hello_module.h

2)编辑config.m4文件,我们使用enable-hello_module选项:

dnl PHP_ARG_ENABLE(hello_module, whether to enablehello_module support,

dnl Make sure that the comment is aligned:

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

修改成

PHP_ARG_ENABLE(hello_module, whether to enable hello_module support,

[  --enable-hello_module           Enable hello_module support])

3)vi hello_module.c

主要是给模块添加函数:

/* Every user visible function must have an entry in my_module_functions[].*/

function_entry hello_module_functions[] = {

PHP_FE(hello_world,    NULL) /* 添加着一行代码 */

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(hello_world)

{

zend_printf("hello sdomain!");

}

4)修改php_hello_module.h

在PHP_FUNCTION(confirm_my_module_compiled ); /* For testing, remove later. */ 这行的下面添加一行:

PHP_FUNCTION(hello_world); /* 函数的声明 */

我这里直接在文件最底下加上

PHP_FUNCTION(hello_world); /* 函数的声明 */

5) 执行phpize并编译

JesusSlimsMBFuxkingP:hello_module jesusslim$ /Applications/MAMP/bin/php/php5.6.6/bin/phpize

0818b9ca8b590ca3270a3433284dd417.png

然后执行:

JesusSlimsMBFuxkingP:hello_module jesusslim$ ./configure --enable-hello_module --with-php-config=/Applications/MAMP/bin/php/php5.6.6/bin/php-config

JesusSlimsMBFuxkingP:hello_module jesusslim$ make

这个时候会在当前的目录下生成一个目录叫modules先存放着hello_module.so文件

cp modules/hello_module.so     /usr/local/php/ext/

然后再把

hello_module.so文件拷到php.ini里面的extension_dir所指定的位置

6)开启扩展

php.ini文件中打开这个扩展

extension=hello_module.so

重新起动apache

用phpinfo来查看

调用直接hello_world();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值