日期:2014-05-16  浏览次数:20686 次

Linux环境用C编写PHP扩展

编写从一个helloworld开始

1:先去网上下载php源码

2:下载来后解压,进入ext目录

3:利用ext_skel

./ext_skel --extname=hellowworld

4:进行hellowworld目录,修改config.m4文件,注释掉(注释,实际上也就是去掉前面的dnl)

PHP_ARG_ENABLE(myfunctions, whether to enable myfunctions support,
Make sure that the comment is aligned:
[  --enable-myfunctions           Enable myfunctions support])

5:用phpisze来创建

/usr/local/php/bin/phpisze

 ./configure --with-php-config=/usr/local/php/bin/php-config

make

会报错,undefined PHP_FE_END

搞不清楚状态,总之编辑hellowworld.c,将PHP_FE_END修改为

{NULL,NULL,NULL}

然后重新

make&&make install

成功编译,新编译得模块在

/usr/local/php/lib/extensions/no-debug-non-zts-20060613 目录下

然后编辑php.ini,加入该模块

extension=hellowworld.so

重新apache,然后写一个页面

<?php
 echo phpinfo();

查看一下,是否存在hellowworld模块,

本次非常简单,生成了hellowword拓展,但是该扩展并没有任何函数,如果需要写函数,请参考其他文档,