乐博体育

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

教你如何自学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个性字。


五 步,资源调用测验


本人写的phpjs,调节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"});