1. 擴(kuò)展你的php
2. 擴(kuò)展的3種方式
3. extension dll方式的擴(kuò)展
4. 小結(jié)
首先注意, 以下所有的一切皆在win下進(jìn)行, 使用的工具的vc++6.0.
擴(kuò)展你的PHP
PHP以方便快速的風(fēng)格迅速在web系統(tǒng)開發(fā)中占有了重要地位. PHP本身提供了豐富的大量的函數(shù)及功能. 長話短說. 我們看看我們?nèi)绾芜M(jìn)行擴(kuò)展.
擴(kuò)展的3種方式
External Modules
Built-in Modules
The Zend Engine
3種方式的優(yōu)缺點(diǎn)可參見PHP手冊.http://www.php.net/manual/en/zend.possibilities.php
extension dll
1. 首先我們?nèi)ハ聜€(gè)php的source. 可以看到有以下幾個(gè)重要的目錄.
ext, main, TSRM, Zend, 另外我們可能還需要bindlib_w32(需要你從cvs上下), 及PHP目錄下的php4ts.lib
2. 打開VC, 新建一個(gè)Win32 Dynamic-Link Library, 如下圖
3. 點(diǎn)ok, 選擇'An Empty Dll Project', and click finish.
4. 設(shè)置Build的Active Configuration. 選Release:)
5. Project->settings.
預(yù)定義標(biāo)識. 整個(gè)如下.ZEND_DEBUG=0,COMPILE_DL_BINZY,ZTS=1,ZEND_WIN32,PHP_WIN32,HAVE_BINZY=1
這個(gè)是包含路徑,上面所提及的幾個(gè)路徑都可以加入.
選擇Multithreaded DLL,
取名時(shí)隨便的, 要link php4ts.lib~~ :)
o, 忘了, 別忘了加上 /Tc的參數(shù).
6. 寫代碼.
建個(gè)頭,建個(gè)身體.
Binzy.h
// Binzy Wu // 2004-4-9 // PHP Extension #if HAVE_BINZY extern zend_module_entry binzy_module_entry; #define binzy_module_ptr &binzy_module_entry PHP_FUNCTION(hellobinzy); // PHP_MINFO_FUNCTION(binzy); // #endif
// Binzy Wu // 2004-4-9 // PHP Extension #include "php.h" #include "Binzy.h" #if HAVE_BINZY #if COMPILE_DL_BINZY ZEND_GET_MODULE(binzy) #endif function_entry binzy_functions[] = { PHP_FE(hellobinzy, NULL) {NULL, NULL, NULL} }; zend_module_entry binzy_module_entry = { STANDARD_MODULE_HEADER, "binzy", binzy_functions, NULL, NULL, NULL, NULL, PHP_MINFO(binzy),
NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; PHP_MINFO_FUNCTION(binzy) { php_info_print_table_start(); php_info_print_table_row(2, "Binzy Extension", "Enable"); php_info_print_table_end(); } PHP_FUNCTION(hellobinzy) { zend_printf("Hello Binzy"); } #endif<? hellobinzy(); ?>
hoho~~~
phpinfo();
小結(jié)
這算入門篇, 以后再一步步來~~. 慢慢深入, 有些我也不了解的。 偶是初學(xué)者。
Binzy Wu
有任何疑問請到討論區(qū)參加本文章相關(guān)討論:http://club.phpe.net/index.php?act=ST&f=15&t=4809
注:本文章版權(quán)歸文章作者與超越PHP網(wǎng)站所有,未經(jīng)超越PHP網(wǎng)站同意,禁止任何商業(yè)轉(zhuǎn)載。非盈利網(wǎng)站及個(gè)人網(wǎng)站轉(zhuǎn)載請注明出處,謝謝合作!
新聞熱點(diǎn)
疑難解答