php语言自带了很多的扩展模块,诸如mbstring、gd、pdo等等。有时为了提高效率,需要用C实现其中的一些功能,就可以自行编写php的扩展模块
系统是ubuntu 12.04,已经安装好了apache和php,php的版本是5.3.10。
以下操作如果碰到权限方面的问题,建议切换成root操作。
1、下载源码
签出php 5.3.10的源代码
代码如下:
Tips:如果没有这个命令,需要先安装svn,在ubuntu下直接使用apt-get安装就OK了:
代码如下:
$ sudo apt-get install subversion
关于php源码,如需要了解更多信息,可以查看php维基中关于svn的说明:https://wiki.php.net/vcs/svnfaq
2、创建模块
a、源码签出完毕后,进入源码e来源gaodaima#com搞(代@码网xt目录,先用ext_skel创建一个模块, 模块名为my:
代码如下:
$ ./ext_skel –extname=my
b、进入my模块:
代码如下:
$ cd my
c、修改config.m4文件,找到如下内容:
代码如下:
dnl PHP_ARG_WITH(my, for my support,
dnl Make sure that the comment is aligned:
dnl [ –with-my Include my support])
dnl Make sure that the comment is aligned:
dnl [ –with-my Include my support])
将前面的dnl去除,最后如下:
代码如下:
PHP_ARG_WITH(my, for my support,
Make sure that the comment is aligned:
[ –with-my Include my support])
Make sure that the comment is aligned:
[ –with-my Include my support])
然后保存文件。
Tips:如果需要测试下修改是否正确,可以使用php my.php来测试下:
代码如下:
$ php my.php
confirm_my_compiled
confirm_my_compiled
Congratulations! You have successfully modified ext/my/config.m4. Module my is now compiled into PHP.
以上就是ubuntu12.04使用c编写php扩展模块教程分享的详细内容,更多请关注gaodaima搞代码网其它相关文章!