教你如何自学PHP扩展
本段以PHP7身为语气寻找大体条件,教学教你怎样才能从零慢慢创立了一款PHP延伸。该篇最主要教学创立了一款延伸的大体具体步骤。范本中,你们将改变方式职能:
<?php echo sayWord(); ?>
我让上方的程度执行工作导致为:
$ php ./test.php $ hello word
感觉为在寻找中建立一款 sayWord手段,调节该sayWord手段后,系统软件将工作输出:hello word。后面 ,我将教亲们该手段的建立步奏。
首步,转换代码是什么
这些php为你们供应了非常的棒的出现主要编码是什么的APPext_skel。该APP在php源编码是什么的./ext的目录中。
$ cd php_src/ext/ $ ./ext_skel --extname=sayWord
extname性能参数的值即使加密品牌。进行ext_skel下令后,这些在某些根分类目录下易转化成有一个与加密名一个的根分类目录。
最后步,更该config.m4调试程序
config.m4的意义即使结合phpize生产工具导出configure压缩文档。configure压缩文档是使用情况的判断的。的判断发展编译操作需提交的情况什么情况下符合。接下来咱们准备合并config.m4压缩文档。
$ cd ./sayWord $ vim ./config.m4
开启,config.m4文本后,你可以找到这种一截任何文字。
dnl If your extension references something external, use with: dnl PHP_ARG_WITH(sayWord, for say support, dnl Make sure that the comment is aligned: dnl [ --with-sayWord Include sayWord support]) dnl Otherwise use enable: dnl PHP_ARG_ENABLE(sayWord, whether to enable say support, dnl Make sure that the comment is aligned: dnl [ --enable-sayWord Enable sayWord support])
其中的,dnl 是注音特殊符号。底下的码怎么用怎么用说,可是我所编程的初始化如依靠于沒有的初始化以及lib库,可以删去PHP_ARG_WITH涉及到的码怎么用怎么用的注音。除非,删去 PHP_ARG_ENABLE 涉及到的码怎么用怎么用段的注音。人们编程的初始化不可以依靠于相关的初始化和lib库。因,人们删去PHP_ARG_ENABLE上面的注音。删去注音后的码怎么用怎么用有以下:
dnl If your extension references something external, use with: dnl PHP_ARG_WITH(sayWord, for sayWord support, dnl Make sure that the comment is aligned: dnl [ --with-sayWord Include sayWord support]) dnl Otherwise use enable: PHP_ARG_ENABLE(sayWord, whether to enable sayWord support, Make sure that the comment is aligned: [ --enable-sayWord Enable sayWord support])
其3步,代碼实现目标
修改图片sayWord.c文本。保证 sayWord步骤。
查找PHP_FUNCTION(confirm_sayWord_compiled),在其里面多下述编码:
PHP_FUNCTION(sayWord) { zend_string *strg; strg = strpprintf(0, "hello word"); RETURN_STR(strg); }
寻找 PHP_FE(confirm_sayWord_compiled, 在上方增多以下的二维码:
PHP_FE(sayWord, NULL)
重设后的代码是什么下面的:
const zend_function_entry say_functions[] = { PHP_FE(sayWord, NULL) /* For testing, remove later. */ PHP_FE(confirm_sayWord_compiled, NULL) /* For testing, remove later. */ PHP_FE_END /* Must be the last line in sayWord_functions[] */ }; /* }}} */
4.步,编译按装
编译括展的进行如表:
$ phpize $ ./configure $ make && make install
变更php.ini信息,不断增加给出编码:
[sayWord] extension = sayWord.so
第三强制执行,php -m 强制性。在信息输出的信息中,你是看见sayWordr标志。
五、步,加载測試
本人写一款php按键小精灵,传参sayWord的方式。看导出的游戏内容是不是合适预想。
网站建设首选石家庄尚途网络科技有限公司,更多网站优化,网站建设信息请关注:尚途科技,网址://chixintf.com