Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    Louisville, KY
    Posts
    11

    Unanswered: Apache::DBI configuration question

    I have a Perl CGI website that is using DBI to interface with Oracle. I want to use Apache:: DBI so that DB requests will come from a pool. At CPAN, it promises that I will not have to change my existing scripts to use Apache:: DBI along with DBI.

    I have mod_perl compiled into my web server, but currently none of my scripts are using Apache::PerlRun or Apache::Registry.

    Does using Apache:: DBI force me to use Apache::PerlRun or Apache::Registry as well? I have an awful lot of scripts that access the DB.... I tried running them all thru PerlRun before and it brought the system to its knees.

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    I would recommend to create an own module, where the database-connection is set up. Then you have to use this module in your scripts. So you have just one persistant connection.

    Can you post the (important part of the) configuration of your Apache?
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Apr 2004
    Location
    Louisville, KY
    Posts
    11
    Originally posted by reneeb
    I would recommend to create an own module, where the database-connection is set up. Then you have to use this module in your scripts. So you have just one persistant connection.

    Can you post the (important part of the) configuration of your Apache?
    The problem is that I need more than one persistant connection- I need a pool of them. It is a web application with many concurrent users, and some Db interactions can take as long as 5 minutes.

    In this application I have many vanilla Perl CGI scripts which are already written, which currently do not go thru the mod_perl pathway, and which initiate their own DBI (plain old DBI, not Apache:: DBI) connections. I was hoping that I could load Apache:: DBI, therefore working behind the scenes to create a pooling mechanism for my application. It seemed like this was the case acc to the docs on CPAN.

    I don't want to change a lot of source code. I just want Apache:: DBI to handle the pooling like it says it will.

    So my question still is: Do my existing CGI scripts need to go thru Apache::PerlRun or Apache::Registry for Apache:: DBI to work?

  4. #4
    Join Date
    Apr 2004
    Posts
    16
    Apache::DBI is able to keep the database connection persistant because the handlers stay loaded in Apache. CGI has no way of interfacing with things at such a low level, and thus cannot take advantage of any database connections Apache keeps pooled.

    The only way you will be able to make a persistant db connection in a cgi is to use something like a database proxy. This is way more trouble than it is worth. From here you will need to implement some sort of auth again and basically you run into the same problems all over again. You should simply use mod_perl if you are concerned about performance. The simple act of spawning a process for a CGI script is killer anyways.

    Avoiding spawning of a process and reconnecting to a database are the two biggest speed boosts mod_perl gives you and Apache::Request addresses both of these issues. Apache::Request requires basically no changes on your part except a couple lines in the config files. Apache::Request takes very little or no effort since it runs almost all CGI scripts untouched as long as they are written well (use strict, use warnings, and that will cover most problems. if the code isnt doing this anyways, its time for a rewrite and a new programmer)

    Using your own module to do the connection like reneeb suggested will do nothing to help you in a CGI script because each call to a CGI makes a new process. The modules will be fully disposed each call.
    Last edited by mkc; 04-21-04 at 04:45.
    perl -le 'print reverse reverse "just another perl hacker"'
    wush.net subversion hosting - remote hosted revision control with easy admin, ssl security & backups

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •