Consdirations for making multiple handlers in same apache module or having seperate modules for each handler
I am writing an application where there are a bunch of handlers. I am trying to see if i should package these handlers within the same apache module or have a seperate module for each handler.
I agree this is a generic question and would depend on my app, but i would like to know the general considerations th开发者_如何学Cat i have to make and also the trade-offs in each of the approach.
It will be really good if somebody can tell me the advantages/disdvantages of both approaches.
You have not specified if all these handlers need to perform some interrelated tasks or are they going to work independently of each other.
I would go for keeping the related handlers in the same module, and rest of them in their own module. I believe it makes the configuration of the server easy (we can easily load/unload a module as required) and the code base remains well managed too.
For instance suppose we needed two handlers that share some data, then we could keep then in the same module:
static int my_early_hook(request_rec
*r) {
req_cfg *mycfg = apr_palloc(r->pool, sizeof(req_cfg));
ap_set_module_config(r->request_config,
&my_module, mycfg);
/* set module data */ }
static int my_later_hook(request_rec
*r) {
req_cfg *mycfg = ap_get_module_config(r->request_config,
&my_module);
/* access data */ }
精彩评论