views:

13

answers:

1

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 that 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.

A: 

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 */ }
Abhinav Upadhyay
yes, the handlers need to do tasks which has some data sharing. Would that mean they have to be in the same module?
AJ
not necessarily. Its easier to share data if they are in same module, as I showed in the above code, but two modules can also share data between them using the notes table inside the request_rec object. If your overall aim is to achieve a particular output using these different handlers then you should consider putting them inside the same module. There are different kinds of modules, some of them are 1 file module while others are well separated in 2 or 3 different modules.
Abhinav Upadhyay