当前位置: 首页 > 图文教程 > 网络编程 > PHP > 扩展你的 PHP 之入门篇

PHP
《PHP设计模式介绍》第十三章 适配器模式
《PHP设计模式介绍》第十四章 动态记录模式
《PHP设计模式介绍》第十五章 表数据网关模式
《PHP设计模式介绍》第十六章 数据映射模式
《PHP设计模式介绍》第十七章 MVC 模式
Zend Framework 入门——快速上手
Zend Framework 入门——多国语言支持
Zend Framework 入门——错误处理
Zend Framework 入门——页面布局
详细介绍php5编程中的异常处理
PHP5 OOP编程中的代理与异常
PHP程序的常见漏洞攻击分析
PHP.MVC的模板标签系统
PHP教程:PHP编码书写规范
PHP开发大型项目的方法:OOP思想
php使用curl模拟用户登陆
php对gb编码动态转utf-8编码的几种方法评测
php设计模式介绍之章代理模式
“在phpMyAdmin使用用户口令登陆”补充
PHP入门速成

扩展你的 PHP 之入门篇


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 91 ::
收藏到网摘: n/a

扩展你的php

  1. 扩展你的php
  2. 扩展的3种方式
  3. extension dll方式的扩展
  4. 小结

  首先注意,以下所有的一切皆在 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”,点击完成。
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

7、编译,修改 php.ini,restart apache,写个 php

<?php
hellobinzy
();
?>

hoho~~~

phpinfo();

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