that way it won't have unused connections waiting to time out or anything that could cause bad things to happen

I'm afraid chances are in general that more bad things will happen when you try to use shared DB connections with CGI scripts ;)   Anyhow, if you really need to do so (for performance reasons), you might want to look into connect_cached, or Apache::DBI (when using mod_perl).  But in this case be particularly careful with forking in combination with persistent DB connections (see InactiveDestroy).

Also note that "normal" CGI scripts start up a new process for every HTTP request, but you'd rather want persistent request handlers that allow to keep a DB connection open — as offered by FastCGI or mod_perl.  Otherwise, you'd have to have a separate "connection broker" (a persistently running process) that you connect to from the CGI script (e.g. via a socket) in order to delegate the DB query to a free DB handle from a pool of handles managed by the broker (in the hopes that the communication overhead with the broker is less than the overhead resulting from simply opening a new DB connection every time...)


In reply to Re: Looking for a way to use one database connection with multiple CGI scripts by almut
in thread Looking for a way to use one database connection with multiple CGI scripts by vendion

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.