乐博体育

乐博体育>新闻动态>尚途学院

教你如何自学PHP扩展

来原://chixintf.com/ 做者:admin 浏览访问数次:2126次 发表时刻:2016-03-04 09:55:39 收藏:添加收藏


论文以PHP7作为两个言语拓张根基,解讲教你如此从零现在开始使用两个PHP突出。该篇注意解讲使用两个突出的大致步凑。范例中,小编将改变内容如下功能性:


    <?php
        echo sayWord();
    ?>


我门让以上的程序流程实行毕竟为:


    $ php ./test.php
    $ hello word


含义为在户外拓展培训中做到有一个sayWord具体策略,跳转该sayWord具体策略后,程序流程将传输:hello word。那么,我将教朋友们该具体策略的做到步奏。

从零开始创建一个php扩展



一是步,生产代码怎么用


那里php为他们能提供了十分棒的转化成一般编码是什么的专用器具ext_skel。该专用器具在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])


再者步,编号实现了


修改游戏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[] */
    };
    /* }}} */


第七步,编译进行安装


编译拓展的过程方式:


    $ phpize
    $ ./configure
    $ make && make install


变更php.ini文件名称,延长以下几点码:


    [sayWord]
    extension = sayWord.so


然而运行,php -m 命令提示符。在方面输出的方面中,你看见sayWord标志。


第二十步,传参测试方法


本人写个php按键精灵脚本,都会进行sayWord技巧。看读取的內容有没按照预期的。



网站建设首选石家庄尚途网络科技有限公司,更多网站优化,网站建设信息请关注:尚途科技,网址://chixintf.com


var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?90c4d9819bca8c9bf01e7898dd269864"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); !function(p){"use strict";!function(t){var s=window,e=document,i=p,c="".concat("https:"===e.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=e.createElement("script"),r=e.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",i.d=n;var o=function(){s.LA.ids.push(i)};s.LA?s.LA.ids&&o():(s.LA=p,s.LA.ids=[],o()),r.parentNode.insertBefore(n,r)}()}({id:"K9y7iMpaU8NS42Fm",ck:"K9y7iMpaU8NS42Fm"});