You can use hook_init to initialize a resource that will last longer than a request or connection.
typedef struct { apr_pool_t *pool; apr_hash_t *hash; } my_server_config; static void my_child_init(apr_pool_t *p, server_rec *s) { my_server_config cfg = ap_get_module_config(s->module_config, &my_module); } static void my_register_hooks(apr_pool_t *p) { ap_hook_child_init(my_child_init, NULL, NULL, APR_HOOK_MIDDLE); } module AP_MODULE_DECLARE_DATA my_module = { STANDARD20_MODULE_STUFF, NULL, NULL, NULL, NULL, NULL, my_register_hooks, };
A child initialization hook will be called before apache enters operational mode or before threads are created in streaming MPM. The pool passed to the my_child_init function must be a process pool.
For a better example, you should download the Apache source code and check the modules / experimental / mod_example.c file.
source share