在php開發的過程中,有時候為了提高效能,需要選擇擴充套件的方式去實現,本文簡單介紹怎麼開發乙個簡單的php擴充套件,解開php擴充套件開發的神秘面紗
環境:php 5.2.14 centos 5.5
第一步:建立擴充套件骨架
cd php-5.2.14/ext
./ext_skel –extname=laiwenhui
第二步:修改編譯引數
cd php-5.2.14/ext/laiwenhui
vi config.m4
去掉 php_arg_enable(laiwenhui, whether to enable laiwenhui support,
[ --enable-laiwenhui enable laiwenhui support])
兩行前面的dnl
修改後為:
複製**
**如下:
dnl otherwise use enable:
php_arg_enable(laiwenhui, whether to enable laiwenhui support,
dnl make sure that the comment is aligned:
[ --enable-laiwenhui enable laiwenhui support])
第三步:編寫**
vim php_laiwenhui.h
在 php_function(confirm_laiwenhui_compiled); 後面新增一行:php_function(test);
新增後為:
php_function(confirm_laiwenhui_compiled); /* for testing, remove later. */
php_function(test);
然後 vim laiwenhui.c
在php_fe(confirm_laiwenhui_compiled, null) 後面新增 php_fe(test, null)
新增後為:
複製**
**如下:
zend_function_entry laiwenhui_functions = /* must be the last line in laiwenhui_functions */
}; 在檔案最後面增加如下**:
複製**
**如下:
php_function(test)
第四步:編譯**
複製**
**如下:
cd php-5.2.6/ext/laiwenhui
/opt/module/php/bin/phpize
./configure –with-php-config=/opt/module/php/bin/php-config
make
make install
我的php安裝路徑為:/opt/module/php
這個時候會生成乙個檔案 /opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui.so
vim php.ini
在[php]模組下增加:extension = laiwenhui.so
;extension=php_zip.dll
extension = laiwenhui.so
把php.ini 檔案中的 extension_dir 修改為該目錄:
extension_dir = 「/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/」
; directory in which the loadable extensions (modules) reside.
extension_dir = 「/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/」
第五步:檢查安裝結果
1. 重啟apache或者php-fpm
2. /opt/module/php/bin/php -m 看下是否有包含laiwenhui擴充套件。
第六步:執行測試**
在**根目錄建立test.php
vim test.php
**內容如下
<?php
echo test();
?>
執行後結果為:this my first extention!
如果你能順利完成以上幾步,恭喜你完成了第乙個擴充套件。
0
給主人留下些什麼吧!~~
PHP擴充套件開發常用巨集介紹
name 函式名 arg info 函式引數定義資訊 example const zend function entry xml functions 最常用的就是下面三個,定義在zend api.h當中.zend begin arg info ex name 鍵名,規範命名都是函式名 arginfo...
php擴充套件開發
php擴充套件 pecl 跟php引擎一樣都是使用c語言開發。php核心開發組成員鳥哥laruence使用的是vim進行php開發。書籍 案例 php src ext pecl開發郵件組 盡量編寫一些phpt測試用例,php src tests下有很多參考.測試時用 enable debug編譯ph...
php擴充套件開發
二 php擴充套件開發 擴充套件開發流程 生成開發骨架 修改config.m4 編碼 編譯擴充套件為so 修改php.ini 1.生成開發骨架 1.1 進入擴充套件目錄 cd php 7.0.1 ext 1.2 用.ext skel生成骨架 ext skel extname module 1.3 修...