Start, terminate, and some of these points
In this book, you have used the Minit function several times to perform initialization tasks when PHP loads your extended shared library. In the 1th chapter, "Life Cycle of PHP," You also learned about the other three startup/termination functions, which correspond to the Minit Mshutdown, and a pair of rinit/rshutdown methods that are invoked at the start and end of each page request.
Life cycle
In addition to these four functions that are directly linked to the module structure, there are also two functions that are used only in the thread environment to handle the start and end of each thread, and what they use as storage space. Before you begin, copy your PHP extension skeleton program to the ext/sample4 of the PHP source tree. The code is as follows
Config.m4
Php_arg_enable (Sample4,
[Whether to enable the "sample4" extension],
[ enable-sample4 Enable] Sample4 "extension support]"
if test $PHP _sample4!= "No"; then Php_subst
(sample4_shared_libadd)
Php_new_ EXTENSION (Sample4, sample4.c, $ext _shared)
fi
Php_sample4.h
#ifndef php_sample4_h/
* Prevent double inclusion */
#define PHP_SAMPLE4_H/
* Define Extension Properties * *
#define Php_sample4_extname "sample4"
#define Php_sample4_extver "1.0"/
* Import Configure Options when
building outside to
the PHP source tree */
#ifdef have_config_h
#include "config.h"
#endif/
* Include PHP Standard Header/
#include "php.h"/*
Define The entry point symbol
* Zen D'll use when loading this module
*
/extern zend_module_entry sample4_module_entry;
#define PHPEXT_SAMPLE4_PTR &sample4_module_entry
#endif/* Php_sample4_h *
Sample4.c
#include "php_sample4.h" #include "ext/standard/info.h" static function_entry php_sample4_functions[] = {
{null, NULL, NULL}};
Php_minit_function (sample4) {return SUCCESS;
} php_mshutdown_function (sample4) {return SUCCESS;
} php_rinit_function (sample4) {return SUCCESS;
} php_rshutdown_function (sample4) {return SUCCESS; } php_minfo_function (Sample4) {} zend_module_entry sample4_module_entry = {#if zend_module_api_no >= 20010901 Standard_module_header, #endif php_sample4_extname, Php_sample4_functions, Php_minit (s
AMPLE4), Php_mshutdown (sample4), Php_rinit (sample4), Php_rshutdown (sample4), Php_minfo (SAMPLE4),
#if zend_module_api_no >= 20010901 php_sample4_extver, #endif standard_module_properties}; #ifdef compile_dl_sample4 zend_get_module (sample4) #endif
Note that each start and stop function returns success when it exits. If one of these functions returns failure, the engine thinks that the process fails and interrupts PHP execution.