First off, thanks for the replies from Perrin and Jonathan. Secondly, I
wasn't using the newest Apache::DBI. I'm now using 0.991 and have the
following in my startup.pl:

use Apache::DBI;
use DBI;
Apache::DBI->connect_on_init("DBI:mysql:database=test;host=:/var/lib/mysql/mysql.sock;",
"test", "test",{'RaiseError' => 1});

When I restarted apache, I looked in mysql and I see 10 connections
(show processlist). I'm guessing 1 for each httpd process.

Then inside my handler module I have this:

sub handler {
  $r = shift;
  $q = CGI->new();

  $dbh =
DBI->connect_on_init("DBI:mysql:database=test;host=:/var/lib/mysql/mysql.sock;",
"test", "test",{'RaiseError' => 1});

  $dbh->{HandleError} = sub { &messageDie("A database error has
occured.", shift, shift) };

 ...code..
}

I just ran a quick test using "ab" on another machine. I did 1000
requests and mysql constantly showed those same 10 connections. So I
guess its working now.

I've got 1 final problem with mod_perl2 but I'll use a different subject
line so to start a new thread.

Thanks again,
Matthew

Jonathan Vanasco wrote:

On May 1, 2006, at 5:47 PM, Matthew wrote:

use Apache::DBI;  // this aint working right

what's not working with it?

generally I do this

+ Startup.pl
     Use Apache::DBI

+ DB.pl

my    %_db_config =
(
    dbType     => 'postgresql',
    dbi     => 'dbi:Pg:dbname=x',
    dbUser     => 'x',
    dbPass     => 'x',
    dbArgs     => { RaiseError => 0, AutoCommit => 1 , TraceLevel => 0 },
);
Apache::DBI->connect_on_init( $_db_config{'dbi'}, $_db_config {'dbUser'}, $_db_config{'dbPass'}, $_db_config{'dbArgs'} );
sub dbconnect
{
   $self->_dbconnect_real( \%_db_config )
}

but i write mp handlers, you're just porting

unless someone can chime in quick enough, i'd suggest looking to see where the first db connection is being instantiated. my guess from what you've written, is that you're connecting on the server startup (maybe in startup.pl somewhere?). once apache::DBI is loaded, it caches all connections - so you'll probably get worse performance with every request sharing 1 connection, than with every request making/breaking a new request. you want to make sure that you load Apache::DBI in startup.pl, but that you don't make any connections until you're in an apache request.


| - - - - - - - - - - - - - - - - - - - -
| RoadSound.com / Indie-Rock.net
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - -





Reply via email to