歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 讓PHP更有魅力,擴展你的 PHP 之入門篇

讓PHP更有魅力,擴展你的 PHP 之入門篇

日期:2017/2/27 9:26:42   编辑:更多Linux
  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,如下圖:    [[The No.1 Picture.]]   3、點 ok,選擇“An Empty Dll Project”,點擊完成。    4、設置 Build 的 Active Configuration,選 Release:)    [[The No.2 Picture.]]   5、Project->settings  [[The No.3 Picture.]]   預定義標識. 整個如下:    ZEND_DEBUG=0, COMPILE_DL_BINZY, ZTS=1, ZEND_WIN32, PHP_WIN32, HAVE_BINZY=1    [[The No.4 Picture.]]   這個是包含路徑,上面所提及的幾個路徑都可以加入。  [[The No.5 Picture.]]   選擇 Multithreaded DLL。  [[The No.6 Picture.]]   取名時隨便的,要 link php4ts.lib~~  o,忘了,別忘了加上 /Tc 的參數  [[The No.7 Picture.]]   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    7、編譯,修改 php.ini,restart apache,寫個 php      [[The No.8 Picture.]]   phpinfo();  [[The No.9 Picture.]]     小結  這算入門篇, 以後再一步步來~~. 慢慢深入, 有些我也不了解的。 偶是初學者。




Copyright © Linux教程網 All Rights Reserved