Perl: the Markov chain saw | |
PerlMonks |
sharing a complex set of objects between httpd processesby thpfft (Chaplain) |
on Mar 15, 2003 at 01:42 UTC ( [id://243231]=perlquestion: print w/replies, xml ) | Need Help?? |
thpfft has asked for the wisdom of the Perl Monks concerning the following question: I'll try and make this quick, because I know it's just a mixture of common questions but I've searched most diligently and can't find a definitive answer. My application offers a singleton factory object as its front end: factory because if you pass it TT2 it gives the template author access to a wide range of classes, singleton because it's an expensive object and I don't want to have to make one for each request. It's initialised in a startup.pl, and thereafter every handler gets the same factory. All this works fine within an httpd process: all requests make use of the same factory and therefore the same Config and Template and what have you. The next step is obvious: how can I get all of the httpd processes to share that single factory object and all its attendant machinery? They may have to share more than one object of this class, by the way: if two sites are running this application they'll have one factory each. I know of various solutions that involve holding bits of data in a place that all the processes can reach - from Apache::Session hashes to dot files and databases - and others that use formal IPC and shared memory. It just seems like too much engineering: serialise this, synchronise that, tie up and flock the other. I've got a database for that sort of thing: I just need to share the means of getting at it. In short, I want to create a single factory, give it to each httpd child as it starts up, and leave them all to get on with it. I suppose that means I need to require the relevant classes and create the factory at some very early stage of the startup process that happens before children are spawned. If anyone can either tell me how to do that or tell me where I'm being stupid, I'll be very grateful indeed.
Back to
Seekers of Perl Wisdom
|
|