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.


In reply to sharing a complex set of objects between httpd processes by thpfft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.