歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> PHP開發學堂:擴展你的PHP之入門篇

PHP開發學堂:擴展你的PHP之入門篇

日期:2017/2/27 9:33:59   编辑:更多Linux
  首先注意, 以下所有的一切皆在win下進行, 使用的工具的vc++6.0.    擴展你的PHP  PHP以方便快速的風格迅速在web系統開發中占有了重要地位. PHP本身提供了豐富的大量的函數及功能. 長話短說. 我們看看我們如何進行擴展.    擴展的3種方式  External Modules  Built-in Modules  The Zend Engine  3種方式的優缺點可參見PHP手冊.http://www.php.net/manual/en/zend.possibilities.php    extension dll  1. 首先我們去下個php的source. 可以看到有以下幾個重要的目錄.  ext, main, TSRM, Zend, 另外我們可能還需要bindlib_w32(需要你從cvs上下), 及PHP目錄下的php4ts.lib    2. 打開VC, 新建一個Win32 Dynamic-Link Library, 如下圖     3. 點ok, 選擇'An Empty Dll Project', and click finish.    4. 設置Build的Active Configuration. 選Release:)     5. Project->settings.     預定義標識. 整個如下.ZEND_DEBUG=0,COMPILE_DL_BINZY,ZTS=1,ZEND_WIN32,PHP_WIN32,HAVE_BINZY=1     這個是包含路徑,上面所提及的幾個路徑都可以加入.     選擇Multithreaded DLL,     取名時隨便的, 要link php4ts.lib~~ :)  o, 忘了, 別忘了加上 /Tc的參數.     6. 寫代碼.    建個頭,建個身體.  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.c  // 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    6. 編譯...修改php.ini, restart apache, 寫個php      hoho~~~     phpinfo();




Copyright © Linux教程網 All Rights Reserved