专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Linux » 如何更有魅力:让PHP更有魅力,扩展你的 PHP 之入门篇 »正文

如何更有魅力:让PHP更有魅力,扩展你的 PHP 之入门篇

来源: 发布时间:星期四, 2008年12月4日 浏览:27次 评论:0

  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
  
    hellobinzy();
  ?>
  
[[The No.8 Picture.]]

  phpinfo();
  
[[The No.9 Picture.]]

  
  小结
  这算入门篇, 以后再一步步来~~. 慢慢深入, 有些我也不了解的。 偶是初学者。
  
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: