ubuntu12.04使用c编写php扩展模块教程分享
linux  /  管理员 发布于 3年前   152
系统是ubuntu 12.04,已经安装好了apache和php,php的版本是5.3.10。 以下操作如果碰到权限方面的问题,建议切换成root操作。 1、下载源码 签出php 5.3.10的源代码 Tips:如果没有这个命令,需要先安装svn,在ubuntu下直接使用apt-get安装就OK了: 关于php源码,如需要了解更多信息,可以查看php维基中关于svn的说明:https://wiki.php.net/vcs/svnfaq 2、创建模块 a、源码签出完毕后,进入源码ext目录,先用ext_skel创建一个模块, 模块名为my: b、进入my模块: c、修改config.m4文件,找到如下内容: 将前面的dnl去除,最后如下: 然后保存文件。 Tips:如果需要测试下修改是否正确,可以使用php my.php来测试下: Congratulations! You have successfully modified ext/my/config.m4. Module my is now compiled into PHP. 上面confirm_my_compiled就是模块默认的函数,后面将该模块加载后,就可以调用这个函数了。 3、编译模块 还是在my模块的目录下执行下面命令: 编译成功后,会提示这样的信息: 表示模块已经编译完成,并且复制到php模块目录了。 Tips:如果phpize命令没有找到,需要安装下php5-dev,在ubuntu下直接使用apt-get安装就OK了。 4、加载模块 编辑文件: 增加如下内容,表示加载my.so模块,然后保存。 重新启动apache 在web环境下,可以用phpinfo看看是否加载my模块了。终端可以使用php -i | less查看。 5、编写测试程序 如果上面都执行顺利,那么my模块就加载进来了,my模块的默认的一个方法confirm_my_compiled也就可以调用了。编写php测试文件: 执行测试文件,如果看到下面的输出,那么就成功了。 123 在 原梓番博客 在 博主 在 1111 在 路人 在
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
$ svn checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_3_10/
$ sudo apt-get install subversion
$ ./ext_skel --extname=my
$ cd my
dnl PHP_ARG_WITH(my, for my support,
dnl Make sure that the comment is aligned:
dnl [ --with-my Include my support])
PHP_ARG_WITH(my, for my support,
Make sure that the comment is aligned:
[ --with-my Include my support])
$ php my.php
confirm_my_compiled
$ phpize
$ ./configure
$ make
$ make install
Installing shared extensions: /usr/lib/php5/20090626+lfs/
$ apt-get install php5-dev
$ vim /etc/php5/conf.d/my.ini
extension=my.so
$ /etc/init.d/apache2 restart
echo confirm_my_compiled("Hello");
Congratulations! You have successfully modified ext/my/config.m4. Module Hello is now compiled into PHP.
您可能感兴趣的文章: