|
Declaration of the Zend Module Block
This block is stored in the structure
zend_module_entry and contains all necessary
information to describe the contents of this module to Zend. You can
see the internal definition of this module in
例子 31-2.
例子 31-2. Internal declaration of zend_module_entry. typedef struct _zend_module_entry zend_module_entry;
struct _zend_module_entry {
unsigned short size;
unsigned int zend_api;
unsigned char zend_debug;
unsigned char zts;
char *name;
zend_function_entry *functions;
int (*module_startup_func)(INIT_FUNC_ARGS);
int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);
int (*request_startup_func)(INIT_FUNC_ARGS);
int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS);
void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS);
char *version;
[ Rest of the structure is not interesting here ]
}; |
|
In our example, this structure is implemented as follows:
zend_module_entry firstmod_module_entry =
{
STANDARD_MODULE_HEADER,
"First Module",
firstmod_functions,
NULL, NULL, NULL, NULL, NULL,
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES,
}; |
This is basically the easiest and most minimal set of values you
could ever use. The module name is set to First
Module, then the function list is referenced, after which
all startup and shutdown functions are marked as being unused.
For reference purposes, you can find a list of the macros involved
in declared startup and shutdown functions in
表格 31-3. These are
not used in our basic example yet, but will be demonstrated later
on. You should make use of these macros to declare your startup and
shutdown functions, as these require special arguments to be passed
(INIT_FUNC_ARGS and
SHUTDOWN_FUNC_ARGS), which are automatically
included into the function declaration when using the predefined
macros. If you declare your functions manually and the PHP
developers decide that a change in the argument list is necessary,
you'll have to change your module sources to remain compatible.
表格 31-3. Macros to Declare Startup and Shutdown Functions Macro | Description | ZEND_MINIT(module) |
Declares a function for module startup. The generated name will
be zend_minit_<module> (for example,
zend_minit_first_module). Use in
conjunction with ZEND_MINIT_FUNCTION.
| ZEND_MSHUTDOWN(module) |
Declares a function for module shutdown. The generated name
will be zend_mshutdown_<module> (for
example, zend_mshutdown_first_module). Use
in conjunction with ZEND_MSHUTDOWN_FUNCTION.
| ZEND_RINIT(module) |
Declares a function for request startup. The generated name
will be zend_rinit_<module> (for
example, zend_rinit_first_module). Use in
conjunction with ZEND_RINIT_FUNCTION.
| ZEND_RSHUTDOWN(module) |
Declares a function for request shutdown. The generated name
will be zend_rshutdown_<module> (for
example, zend_rshutdown_first_module). Use
in conjunction with ZEND_RSHUTDOWN_FUNCTION.
| ZEND_MINFO(module) |
Declares a function for printing module information, used when
phpinfo() is called. The generated name will
be zend_info_<module> (for example,
zend_info_first_module). Use in conjunction
with ZEND_MINFO_FUNCTION.
|
| |