<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                本文是以PHP7作為基礎,講解如何從零開始創建一個PHP擴展。本文主要講解創建一個擴展的基本步驟都有哪些。示例中,我們將實現如下功能: ```php <?php echo say(); ?> ``` 輸出內容: ``` $ php ./test.php $ hello word ``` 在擴展中實現一個say方法,調用`say`方法后,輸出 `hello word`。 ### 第一步:生成代碼 PHP為我們提供了生成基本代碼的工具 ext_skel。這個工具在PHP源代碼的./ext目錄下。 ``` $ cd php_src/ext/ $ ./ext_skel --ext say ``` `ext`參數的值就是擴展名稱。執行`ext_skel`命令后,這樣在當前目錄下會生成一個與擴展名一樣的目錄。 ### 第二步,修改config.m4配置文件 `config.m4`的作用就是配合`phpize`工具生成`configure`文件。`configure`文件是用于環境檢測的。檢測擴展編譯運行所需的環境是否滿足。現在我們開始修改`config.m4`文件。 ``` $ cd ./say $ vim ./config.m4 ``` 打開,config.m4文件后,你會發現這樣一段文字。 ``` dnl If your extension references something external, use with: dnl PHP_ARG_WITH(say, for say support, dnl Make sure that the comment is aligned: dnl [ --with-say Include say support]) dnl Otherwise use enable: dnl PHP_ARG_ENABLE(say, whether to enable say support, dnl Make sure that the comment is aligned: dnl [ --enable-say Enable say 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(say, for say support, dnl Make sure that the comment is aligned: dnl [ --with-say Include say support]) dnl Otherwise use enable: PHP_ARG_ENABLE(say, whether to enable say support, Make sure that the comment is aligned: [ --enable-say Enable say support]) ``` ### 第三步,代碼實現 修改say.c文件。實現say方法。 找到`PHP_FUNCTION(confirm_say_compiled)`,在其上面增加如下代碼: ``` PHP_FUNCTION(say) { zend_string *strg; strg = strpprintf(0, "hello word"); RETURN_STR(strg); } ``` 找到 PHP_FE(confirm_say_compiled, 在上面增加如下代碼: ``` PHP_FE(say, NULL) ``` 修改后的代碼如下: ``` const zend_function_entry say_functions[] = { PHP_FE(say, NULL) /* For testing, remove later. */ PHP_FE(confirm_say_compiled, NULL) /* For testing, remove later. */ PHP_FE_END /* Must be the last line in say_functions[] */ }; /* }}} */ ``` ### 第四步,編譯安裝 編譯擴展的步驟如下: ``` $ phpize $ ./configure $ make && make install ``` 修改php.ini文件,增加如下代碼: ``` [say] extension = say.so ``` 然后執行,`php -m` 命令。在輸出的內容中,你會看到`say`字樣。 ### 第五步,調用測試 自己寫一個腳本,調用say方法。看輸出的內容是否符合預期。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看