为什么要写扩展,这里就不在展开说了,网上有很多这方面的知识,这里只说明下开发一个扩展的几个步骤:
1,cd /usr/local/src/php-5.3.6/ext,切换到php的代码目录下
2,./ext_skel --extname=your_ex_tname 使用ext_skel创建一个扩展的框架
1. $ cd ..
2. $ vi ext/your_ext_name/config.m4
3. $ ./buildconf
4. $ ./configure --[with|enable]-your_ext_name
5. $ make
6. $ ./php -f ext/your_ext_name/your_ext_name.php
7. $ vi ext/your_ext_name/your_ext_name.c
8. $ make
3,安装第二部的提示,修改config.m4
去掉
dnl PHP_ARG_ENABLE(your_ext_name, whether to enable your_ext_name support,
dnl Make sure that the comment is aligned:
dnl [ --enable-your_ext_name Enable your_ext_name support])
修改后为:
PHP_ARG_ENABLE(your_ext_name, whether to enable your_ext_name support,
Make sure that the comment is aligned:
[ --enable-your_ext_name Enable your_ext_name support])
4,编写扩展的代码:
vim your_ext_name.h在PHP_FUNCTION(confirm_your_ext_name_compiled);下面增加声明函数
vim your_ext_name.c编写实现代码
5,编译代码:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
6,修改php.ini加载your_ext_name.so,重启web server后用phpinfo查看扩展是否加载成功。