sapi_xxx_module()
| From: | Sascha Schumann | Date: | Fri, 27 Aug 1999 23:39:17 +0000 |
| Subject: | sapi_xxx_module() | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3790@lists.php.net to get a copy of this message | ||
To be able to run startup/shutdown functions from
sapi_startup() and sapi_shutdown(), I've implemented a logic
similar to the one used in internal_functions.c.
It allows modules (I needed it for the shared memory part of
the session module) to register startup/shutdown functions
which are called at server startup/shutdown. I've tested it
with Apache and it appears to do what I need.
Diffs to SAPI.[ch] and SAPI_modules.c attached.
While testing in httpd -X mode I noticed that the Apache
module version calls SAPI immediately in the following order:
sapi_startup()
sapi_shutdown()
sapi_startup()
... end then nothing until the server goes down. It
apparently doesn't call sapi_shutdown() anymore. Hopefully
someone can shed some light on this.
--
Regards,
Sascha Schumann
Consultant
Index: SAPI.c =================================================================== RCS file: /repository/php4/SAPI.c,v retrieving revision 1.27 diff -u -r1.27 SAPI.c --- SAPI.c 1999/08/09 17:40:28 1.27 +++ SAPI.c 1999/08/27 23:32:06 @@ -75,11 +75,13 @@ #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL); #endif -} + sapi_startup_modules(); +} SAPI_API void sapi_shutdown() { + sapi_shutdown_modules(); zend_hash_destroy(&known_post_content_types); } Index: SAPI.h =================================================================== RCS file: /repository/php4/SAPI.h,v retrieving revision 1.18 diff -u -r1.18 SAPI.h --- SAPI.h 1999/07/16 13:12:41 1.18 +++ SAPI.h 1999/08/27 23:32:06 @@ -139,6 +139,18 @@ char *(*read_cookies)(SLS_D); }; +#define SAPI_STARTUP(f) sapi_startup_##f +#define SAPI_SHUTDOWN(f) sapi_shutdown_##f +#define SAPI_STARTUP_FUNC(f) static int SAPI_STARTUP(f)(void) +#define SAPI_SHUTDOWN_FUNC(f) static int SAPI_SHUTDOWN(f)(void) + +typedef struct { + int (*startup)(void); + int (*shutdown)(void); +} sapi_module_entry; + +int sapi_startup_modules(void); +int sapi_shutdown_modules(void); /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) #include "php.h" #include "SAPI.h" #include "ext/session/mod_mm.h" static sapi_module_entry *sapi_modules[] = { sapi_mm_ptr, }; int sapi_startup_modules(void) { sapi_module_entry **ptr = sapi_modules, **end = ptr+(sizeof(sapi_modules)/sizeof(sapi_module_entry *)); while (ptr < end) { if (*ptr && (*ptr)->startup && (*ptr)->startup() == FAILURE) { return FAILURE; } ptr++; } return SUCCESS; } int sapi_shutdown_modules(void) { sapi_module_entry **ptr = sapi_modules, **end = ptr+(sizeof(sapi_modules)/sizeof(sapi_module_entry *)); while (ptr < end) { if (*ptr && (*ptr)->shutdown && (*ptr)->shutdown() == FAILURE) { return FAILURE; } ptr++; } return SUCCESS; }
Index: SAPI.c =================================================================== RCS file: /repository/php4/SAPI.c,v retrieving revision 1.27 diff -u -r1.27 SAPI.c --- SAPI.c 1999/08/09 17:40:28 1.27 +++ SAPI.c 1999/08/27 23:32:06 @@ -75,11 +75,13 @@ #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL); #endif -} + sapi_startup_modules(); +} SAPI_API void sapi_shutdown() { + sapi_shutdown_modules(); zend_hash_destroy(&known_post_content_types); } Index: SAPI.h =================================================================== RCS file: /repository/php4/SAPI.h,v retrieving revision 1.18 diff -u -r1.18 SAPI.h --- SAPI.h 1999/07/16 13:12:41 1.18 +++ SAPI.h 1999/08/27 23:32:06 @@ -139,6 +139,18 @@ char *(*read_cookies)(SLS_D); }; +#define SAPI_STARTUP(f) sapi_startup_##f +#define SAPI_SHUTDOWN(f) sapi_shutdown_##f +#define SAPI_STARTUP_FUNC(f) static int SAPI_STARTUP(f)(void) +#define SAPI_SHUTDOWN_FUNC(f) static int SAPI_SHUTDOWN(f)(void) + +typedef struct { + int (*startup)(void); + int (*shutdown)(void); +} sapi_module_entry; + +int sapi_startup_modules(void); +int sapi_shutdown_modules(void); /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) #include "php.h" #include "SAPI.h" #include "ext/session/mod_mm.h" static sapi_module_entry *sapi_modules[] = { sapi_mm_ptr, }; int sapi_startup_modules(void) { sapi_module_entry **ptr = sapi_modules, **end = ptr+(sizeof(sapi_modules)/sizeof(sapi_module_entry *)); while (ptr < end) { if (*ptr && (*ptr)->startup && (*ptr)->startup() == FAILURE) { return FAILURE; } ptr++; } return SUCCESS; } int sapi_shutdown_modules(void) { sapi_module_entry **ptr = sapi_modules, **end = ptr+(sizeof(sapi_modules)/sizeof(sapi_module_entry *)); while (ptr < end) { if (*ptr && (*ptr)->shutdown && (*ptr)->shutdown() == FAILURE) { return FAILURE; } ptr++; } return SUCCESS; }