Heim  >  Artikel  >  php教程  >  PHP扩展库开发

PHP扩展库开发

WBOY
WBOYOriginal
2016-06-06 19:42:22971Durchsuche

进入到下载的php源码文件中的ext文件夹下 1.cd XXXXX/ext 2.执行ext_skel命令 ./ext_skel --extname=my_module 3.在ext的文件夹下会多出一个名为my_module的文件夹 进入到my_module的文件夹中 cd my_module 4.打config.m4文件 找到如下三行 dnl PHP_ARG_ENAB

进入到下载的php源码文件中的ext文件夹下

1.cd XXXXX/ext

2.执行ext_skel命令

./ext_skel --extname=my_module

3.在ext的文件夹下会多出一个名为my_module的文件夹

进入到my_module的文件夹中

cd my_module

4.打config.m4文件

找到如下三行

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

把这三行前面的dnl去掉,保存

5.修改php_my_module.h文件

在 PHP_FUNCTION(confirm_my_module_compiled);后面加入一行

PHP_FUNCTION(my_func);

6.my_module.c文件的

const zend_function_entry my_module_functions[] = {
    PHP_FE(confirm_my_module_compiled,  NULL)   /* For testing, remove later.     */
    PHP_FE_END  /* Must be the last line in my_module_functions[] */
 };
中加入PHP_FE(my_func,NULL)

加入后的代码如下:

const zend_function_entry my_module_functions[] = {
    PHP_FE(confirm_my_module_compiled,  NULL)   /* For testing, remove later.     */
    PHP_FE(my_func,NULL)
    PHP_FE_END  /* Must be the last line in my_module_functions[] */
 };

7.在my_module.c文件的结尾处加入my_func函数的实现代码

PHP_FUNCTION(my_func){
   php_printf("这是我的第一个扩展库");

 }

8.编译安装自己的扩展库

进入到my_module目录下

cd ext/my_module

执行  /usr/loca/php/bin/phpize

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

make & make install

9.在/usr/loca/php/lib/php/extensions/no-debug-non-zts-XXXX目录下生成了一个my_module.so的文件

打开/usr/local/php/lib/php.ini加入一行配置

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-XXXX/my_module.so

10.生启apache服务

编写一个测试文件test.php

<?php my_func();
?>

打开浏览器输入

localhost/myweb/test.php

回车在浏览器的页面上显示"这是我的第一个扩展库"

至此一个新的php扩展库开发完成

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn