版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
php扩展分为两种.一种是php的扩展,一种是zend扩展.(传说中的,这是programing php里讲的).真的希望能有人发表一些关于zend扩展的东西.这才是真正的核心.
本来是要读下源码的.但是似乎php的源码很多.目前只能扫扫边边角角.如果有机会的话,会去读一下源码的.
其实扩展并不是很难,php已经给好了例子和扩展的工具.使用一下就可以了.
先下php源码,解压
然后到解压目录,ext下 执行./ext_stel --extname=myz
然后到解压目录,执行
./buildconf --force
./configure --with-myz=shared --其他的
make
make install
然后就能看到phpinfo()里面多了个myz了.
这里编译了好几次.好象每次都有新问题.多调试几次一定会成功的."妻儿"不舍
附:php源码包中两个重要的文件内容
README.EXT_SKEL
README.SELF-CONTAINED-EXTENSIONS
README.EXT_SKEL
(NOTE: you may also want to take a look at the pear package
PECL_Gen, a PHP-only alternative for this script that
supports way more extension writing tasks and is
supposed to replace ext_skel completely in the long run ...)
WHAT IT IS
It's a tool for automatically creating the basic framework for a PHP module
and writing C code handling arguments passed to your functions from a simple
configuration file. See an example at the end of this file.
HOW TO USE IT
Very simple. First, change to the ext/ directory of the PHP 4 sources. If
you just need the basic framework and will be writing all the code in your
functions yourself, you can now do
./ext_skel --extname=module_name
and everything you need is placed in directory module_name.
[ Note that GNU awk is likely required for this script to work. Debian
systems seem to default to using mawk, so you may need to change the
#! line in skeleton/create_stubs and the cat $proto | awk line in
ext_skel to use gawk explicitly. ]
If you don't need to test the existence of any external header files,
libraries or functions in them, the module is already almost ready to be
compiled in PHP. Just remove 3 comments in your_module_name/config.m4,
change back up to PHP sources top directory, and do
./buildconf; ./configure --enable-module_name; make
But if you already have planned the overall scheme of your module, what
functions it will contain, their return types and the arguments they take
(a very good idea) and don't want to bother yourself with creating function
definitions and handling arguments passed yourself, it's time to create a
function definitions file, which you will give as an argument to ext_skel
with option
--proto=filename.
FORMAT OF FUNCTION DEFINITIONS FILE
All the definitions must be on one line. In it's simplest form, it's just
the function name, e.g.
my_function
but then you'll be left with an almost empty function body without any
argument handling.
Arguments are given in parenthesis after the function name, and are of
the form 'argument_type argument_name'. Arguments are separated from each
other with a comma and optional space. Argument_type can be one of int,
bool, double, float, string, array, object or mixed.
An optional argument is separated from the previous by an optional space,
then '[' and of course comma and optional space, like all the other
arguments. You should close a row of optional arguments with same amount of
']'s as there where '['s. Currently, it does not harm if you forget to do it
or there is a wrong amount of ']'s, but this may change in the future.
An additional short description may be added after the parameters.
If present it will be filled into the 'proto' header comments in the stubs
code and the <refpurpose> tag in the XML documentation.
An example:
my_function(int arg1, int arg2 [, int arg3 [, int arg4]]) this is my 1st
Arguments arg3 and arg4 are optional.
If possible, the function definition should also contain it's return type
in front of the definition. It's not actually used for any C code generating
purposes but PHP in-source documentation instead, and as such, very useful.
It can be any of int, double, string, bool, array, object, resource, mixed
or void.
The file must contain nothing else but function definitions, no comments or
empty lines.
OTHER OPTIONS
--no-help
By default, ext_skel creates both comments in the source code and a test
function to help first time module writers to get started and testing
configuring and compiling their module. This option turns off all such things
which may just annoy experienced PHP module coders. Especially useful with
--stubs=file
which will leave out also all module specific stuff and write just function
stubs with function value declarations and passed argument handling, and
function entries and definitions at the end of the file, for copying and
pasting into an already existing module.
--assign-params
--string-lens
By default, function proto 'void foo(string bar)' creates the following:
...
zval **bar;
... (zend_get_parameters_ex() called in the middle...)
convert_to_string_ex(bar);
Specifying both of these options changes the generated code to:
...
zval **bar_arg;
int bar_len;
char *bar = NULL;
... (zend_get_parameters_ex() called in the middle...)
convert_to_string_ex(bar_arg);
bar = Z_STRVAL_PP(bar_arg);
bar_len = Z_STRLEN_PP(bar_arg);
You shouldn't have to ask what happens if you leave --string-lens out. If you
have to, it's questionable whether you should be reading this document.
--with-xml[=file]
Creates the basics for phpdoc .xml file.
--full-xml
Not implemented yet. When or if there will ever be created a framework for
self-contained extensions to use phpdoc system for their documentation, this
option enables it on the created xml file.
CURRENT LIMITATIONS, BUGS AND OTHER ODDITIES
Only arguments of types int, bool, double, float, string and array are
handled. For other types you must write the code yourself. And for type
mixed, it wouldn't even be possible to write anything, because only you
know what to expect.
It can't handle correctly, and probably never will, variable list of
of arguments. (void foo(int bar [, ...])
Don't trust the generated code too much. It tries to be useful in most of
the situations you might encounter, but automatic code generation will never
beat a programmer who knows the real situation at hand. ext_skel is generally
best suited for quickly generating a wrapper for c-library functions you
might want to have available in PHP too.
This program doesn't have a --help option. It has --no-help instead.
EXAMPLE
The following _one_ line
bool my_drawtext(resource image, string text, resource font, int x, int y [, int color])
will create this function definition for you (note that there are a few
question marks to be replaced by you, and you must of course add your own
value definitions too):
/* {{{ proto bool my_drawtext(resource image, string text, resource font, int x, int y[, int color])
*/
PHP_FUNCTION(my_drawtext)
{
zval **image, **text, **font, **x, **y, **color;
int argc;
int image_id = -1;
int font_id = -1;
argc = ZEND_NUM_ARGS();
if (argc < 5 || argc > 6 || zend_get_parameters_ex(argc, &image, &text, &font, &x, &y, &color) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(???, ???, image, image_id, "???", ???_rsrc_id);
ZEND_FETCH_RESOURCE(???, ???, font, font_id, "???", ???_rsrc_id);
switch (argc) {
case 6:
convert_to_long_ex(color);
/* Fall-through. */
case 5:
convert_to_long_ex(y);
convert_to_long_ex(x);
/* font: fetching resources already handled. */
convert_to_string_ex(text);
/* image: fetching resources already handled. */
break;
default:
WRONG_PARAM_COUNT;
}
php_error(E_WARNING, "my_drawtext: not yet implemented");
}
/* }}} */
README.SELF-CONTAINED-EXTENSIONS
$Id: README.SELF-CONTAINED-EXTENSIONS,v 1.12 2002/10/23 21:35:17 jon Exp $
=============================================================================
HOW TO CREATE A SELF-CONTAINED PHP EXTENSION
A self-contained extension can be distributed independently of
the PHP source. To create such an extension, two things are
required:
- Configuration file (config.m4)
- Source code for your module
We will describe now how to create these and how to put things
together.
PREPARING YOUR SYSTEM
While the result will run on any system, a developer's setup needs these
tools:
GNU autoconf
GNU automake
GNU libtool
GNU m4
All of these are available from
ftp://ftp.gnu.org/pub/gnu/
CONVERTING AN EXISTING EXTENSION
Just to show you how easy it is to create a self-contained
extension, we will convert an embedded extension into a
self-contained one. Install PHP and execute the following
commands.
$ mkdir /tmp/newext
$ cd /tmp/newext
You now have an empty directory. We will copy the files from
the mysql extension:
$ cp -rp php-4.0.X/ext/mysql/* .
It is time to finish the module. Run:
$ phpize
You can now ship the contents of the directory - the extension
can live completely on its own.
The user instructions boil down to
$ ./configure \
[--with-php-config=/path/to/php-config] \
[--with-mysql=MYSQL-DIR]
$ make install
The MySQL module will either use the embedded MySQL client
library or the MySQL installation in MYSQL-DIR.
DEFINING THE NEW EXTENSION
Our demo extension is called "foobar".
It consists of two source files "foo.c" and "bar.c"
(and any arbitrary amount of header files, but that is not
important here).
The demo extension does not reference any external
libraries (that is important, because the user does not
need to specify anything).
LTLIBRARY_SOURCES specifies the names of the sources files. You can
name an arbitrary number of source files here.
CREATING THE M4 CONFIGURATION FILE
The m4 configuration can perform additional checks. For a
self-contained extension, you do not need more than a few
macro calls.
------------------------------------------------------------------------------
PHP_ARG_ENABLE(foobar,whether to enable foobar,
[ --enable-foobar Enable foobar])
if test "$PHP_FOOBAR" != "no"; then
PHP_NEW_EXTENSION(foobar, foo.c bar.c, $ext_shared)
fi
------------------------------------------------------------------------------
PHP_ARG_ENABLE will automatically set the correct variables, so
that the extension will be enabled by PHP_NEW_EXTENSION in shared mode.
The first argument of PHP_NEW_EXTENSION describes the name of the
extension. The second names the source-code files. The third passes
$ext_shared which is set by PHP_ARG_ENABLE/WITH to PHP_NEW_EXTENSION.
Please use always PHP_ARG_ENABLE or PHP_ARG_WITH. Even if you do not
plan to distribute your module with PHP, these facilities allow you
to integrate your module easily into the main PHP module framework.
CREATING SOURCE FILES
ext_skel can be of great help when creating the common code for all modules
in PHP for you and also writing basic function definitions and C code for
handling arguments passed to your functions. See README.EXT_SKEL for further
information.
As for the rest, you are currently alone here. There are a lot of existing
modules, use a simple module as a starting point and add your own code.
CREATING THE SELF-CONTAINED EXTENSION
Put config.m4 and the source files into one directory. Then, run phpize
(this is installed during make install by PHP 4.0).
For example, if you configured PHP with --prefix=/php, you would run
$ /php/bin/phpize
This will automatically copy the necessary build files and create
configure from your config.m4.
And that's it. You now have a self-contained extension.
INSTALLING A SELF-CONTAINED EXTENSION
An extension can be installed by running:
$ ./configure \
[--with-php-config=/path/to/php-config]
$ make install
ADDING SHARED MODULE SUPPORT TO A MODULE
In order to be useful, a self-contained extension must be loadable
as a shared module. I will explain now how you can add shared module
support to an existing module called foo.
1. In config.m4, use PHP_ARG_WITH/PHP_ARG_ENABLE. Then you will
automatically be able to use --with-foo=shared[,..] or
--enable-foo=shared[,..].
2. In config.m4, use PHP_NEW_EXTENSION(foo,.., $ext_shared) to enable
building the extension.
3. Add the following lines to your C source file:
#ifdef COMPILE_DL_FOO
ZEND_GET_MODULE(foo)
#endif
分享到:
相关推荐
PHP 扩展调用 SO 动态库教程 本篇教程将指导读者如何创建一个 PHP 扩展库,並调用 C 语言编写的共享库。该教程分为两部分,第一部分主要介绍如何创建一个基本的 PHP 扩展库,第二部分则介绍如何在扩展库中调用 C ...
描述中提到“目前企业微信会话内容存档sdk只提供c版本的so以及java版本的so”,这意味着企业微信官方提供的SDK主要是面向C和Java开发者的,而这个PHP扩展是社区或个人开发者为填补PHP支持而创建的。PHP版本要求“>= ...
PHP扩展开发与内核应用主要是一门深入探讨PHP语言的扩展机制和内核实现细节的课程。它旨在教授开发人员如何编写自定义的PHP扩展以及深入理解PHP语言的内部工作原理。在详细讲解这个主题之前,我们首先需要了解几个...
本篇文章将详细介绍如何使用CMake来开发PHP扩展,帮助开发者更好地理解和实践这一过程。 首先,理解PHP扩展的本质:它们是用C或C++编写的库,与PHP解释器交互,提供了新的数据类型、函数和行为。CMake作为构建工具...
"php扩展源码编译包"就是这样一个集合,包含了几个重要的PHP扩展的源代码,包括libxml2、curl、libmcrypt、libpng和zlib。接下来,我们将详细探讨这些扩展及其编译过程。 1. **libxml2**:这是一个强大的XML和HTML...
PHP扩展开发流程是PHP开发者深入理解其内部机制和增强功能的重要途径。以下是一个详细的步骤指南,帮助你了解如何从头开始构建一个PHP扩展。 一、准备环境 1. 安装VC++ 6:这是微软的Visual C++ 6.0编译器,用于...
标题中的“VC建立php扩展”指的是使用Visual C++(VC)编译器来构建PHP的扩展模块。在PHP中,扩展通常用C或C++编写,以增加PHP语言的功能或性能。这一过程涉及到一系列步骤,包括环境配置、代码编写、编译以及安装。 ...
《PHP扩展开发及内核应用》是一本深入探讨PHP扩展编程和PHP内核机制的书籍,基于Sara Golemon的《Extending and Embedding PHP》进行翻译和修订,主要面向那些希望深入了解PHP并可能想要为其开发自定义扩展的开发者...
《PHP扩展开发中文教程》是一本专为对PHP扩展开发感兴趣的开发者量身打造的指南。这本书深入浅出地讲解了如何构建PHP的C语言扩展,从而增强PHP的功能和性能。PHP作为一种广泛使用的开源脚本语言,其核心在于其丰富的...
1. **PHP 扩展.doc**:这份文档应该是PHP扩展的使用和安装指南,可能涵盖了如何启用或禁用扩展,如何编译自定义扩展,以及针对不同操作系统和PHP版本的兼容性信息。它可能还会提供有关配置文件`php.ini`中相关设置的...
在Windows环境下进行PHP扩展开发,通常开发者会遇到各种平台差异问题,因为PHP主要设计于类Unix系统,如Linux。然而,Cygwin提供了一个在Windows上运行Linux/Unix应用程序的解决方案,它创建了一个兼容层,使得...
php扩展peb.so erlang通讯扩展,解决宝塔编译安装php peb扩展编译失败,直接上传到php扩展目录修改配置文件即可使用。
标题中的“ffmpeg-php扩展 ffmpeg.exe php视频格式转换”指的就是使用ffmpeg-php这个PHP扩展,配合ffmpeg.exe可执行文件,实现PHP脚本对视频文件的格式转换功能。这个扩展提供了PHP接口,使得开发者可以轻松地调用...
### Linux下编写自己的PHP扩展 #### 一、概述 在Linux环境下使用C语言编写PHP扩展是一种常见的技术手段,尤其对于那些需要高性能处理的任务而言尤为重要。通过编写PHP扩展,开发者能够利用C语言的强大功能来增强...
让我们从指明为什么你想要编写PHP扩展开始。 1. 限于PHP语言本身的抽象程度,它不能直接访问某些库或特定于操作系统的调用。 2. 你想要通过某些不平常的方法定制PHP的行为。 3. 你有一些现成的PHP代码,但是你知道它...
注意:3.8.1版本重构了PHP扩展,不更新扩展会导致网站出现 此站点遇到了致命错误 ,其他平台购买的就不要到本站来问怎么安装,主题本身就可能有问题,没破解完整你怎么安装都一个样 本资源为PHP修复扩展。 404错误...
SG11扩展下载(php扩展),php插件sg11下载,里面有详细安装教程 SG11扩展下载(php扩展),php插件sg11下载,里面有详细安装教程 SG11扩展下载(php扩展),php插件sg11下载,里面有详细安装教程