Home  >  Article  >  php教程  >  扩展你的PHP之入门篇

扩展你的PHP之入门篇

WBOY
WBOYOriginal
2016-06-21 09:08:011318browse

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', 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



hellobinzy();
?>



hoho~~~




phpinfo();



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

Binzy Wu

有任何疑问请到讨论区参加本文章相关讨论:http://club.phpe.net/index.php?act=ST&f=15&t=4809



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn