JupiterCrash has asked for the wisdom of the Perl Monks concerning the following question:

I have many perl scripts which use dbi/dbd. The scripts themselves are not written in mod_perl, and they cannot easily be converted to mod_perl so that is not an option for me right now.

Under heavy load, performance starts to degrade. I would like to gain the benefits of a persistant database connection that Apache::DBI could provide, but am wondering how big of a task this is. The documentation for Apache::DBI make it seem transparent, as if not much work is required.

Before I bother to setup mod_perl, my question, really, is this: Can I install mod_perl and use Apache::DBI for persistant connections WITHOUT converting all of my existing scripts to run under mod_perl? Will the DBI->Connect call in my non-mod_perl scripts just magically get forwarded to Apache::DBI where a persistant connection is being held open for me?

I would be very happy if I could just install mod_perl and Apache::DBI and start seeing things perform better without doing any other work ... :)

Replies are listed 'Best First'.
Re: Apache::DBI and mod_perl
by valdez (Monsignor) on Oct 24, 2002 at 20:23 UTC

    You need to be running inside mod_perl to take advantage of Apache::DBI connection pooling persistent connections. Please note that you don't need to write any script in mod_perl :) you only need to write some robust Perl code using strict and warnings, plus few simple rules that you can read here: CGI to mod_perl Porting.

    There are some alternatives to mod_perl, like Persistent Perl, but you still need to write code following all the rules that apply to persistent environments.

    Ciao, Valerio

    Update: thank you very much perrin for the correction.

      Probably not a good idea to refer to what Apache::DBI does as "connection pooling." It provides persistent connections, but there is no pooling or really any communication at all between processes.
Re: Apache::DBI and mod_perl
by rdfield (Priest) on Oct 24, 2002 at 20:47 UTC
    Using mod_perl in "PerlRun" mode should mean that you can run your scripts without change and still get persistent DBI connections via Apache::DBI. See the Guide for details.

    rdfield