一,搭建php环境
下载php 5.2.6 源码 并解压
编译安装,搭建php环境
二,创建扩展项目
进入源码目录
cd php5.2.6/ext/
./ext_skel –extname=my_ext
创建名字为my_ext的项目,最终会生成my_ext.so
三,更改配置和程序
$ vi ext/my_ext/config.m4
根据你自己的选择将
dnl php_arg_with(my_ext, for my_ext support,
dnl make sure that the comment任性的反义词 is aligned:
dnl [ –with-my_ext include my_ext support])
修改成
php_arg_with(my_ext, for my_ext support,
make sure that the comment is aligned:
[ –with-my_ext include my_ext support])
或者将
dnl php_arg_enable(my_ext, whether to enable my_ext support,
dnl make sure that the comment is aligned:
dnl [ –enable-my_ext enable my_ext support])
修改成
php_arg_enable(my_ext, whether to enable my_ext support,
make sure that the comment is aligned感动人生:
[ –enable-my_ext enable my_ext support])
$ vi ext/my_ext/php_my_ext.h
将
php_function(confirm_my_ext_compiled); /* for testing, remove later. */
更改为
php_function(say_hello);
$ vi ext/my_ext/my_ext.c
将
zend_function_entry php5cpp_functions[] = {
php_fe(confirm_my_ext_compiled, null) /* for testing, remove later. */
{null, null, null} /* must be the last line in php5cpp_functions[] */
};
更改为
zend_function_entry php5cpp_functions[] = {
php_fe(say_hello, null)
{null, null, null} /* must be the last line in php5cpp_functions[] */
};
在最后添加:
php_function(say_hello)
{
zend_printf(“hello world\n”);
}
四,编译
$ cd my_ext
$ /usr/local/php/bin/significantphpize
ps: 如果出现:cannot find autoconf.……的错误信息,则需要安装 autoconf (安装过程略)
$ ./configure –with-php-config=/usr/local/php/bin/php-config
$ make
这时会编译出 my_ext/modules/my_ext.so
五,配置php.ini
将my_ext.so放入
/u祝福sr/local/php/ext/目录
$ vi php.ini
修改添加如下:
extension_dir = ‘/usr/local/php/ext/’
extension=my_ext.so
六,测试
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
则大功告成
ps:如有问题请留言,大家共同探讨贫困生申请
本文发布于:2023-04-06 14:39:17,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/67babbb463aacae4e2ecb2ceb8860654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:linux下 C语言对 php 扩展.doc
本文 PDF 下载地址:linux下 C语言对 php 扩展.pdf
留言与评论(共有 0 条评论) |