Practical mod_perl / HTML Book /



previous page: 20.2. Improving Performance
  
page up: HTML Version of the book
  
next page: 20.2.2. Improving Speed by Skipping ping( )

20.2.1. Preopening DBI Connections


If you are using Apache::DBI and you want to make sure that a database connection will already be open when your code is first executed within each child process after a server restart, you should use the connect_on_init( ) method in the startup file to preopen every connection that you are going to use. For example:

Apache::DBI->connect_on_init(
    "DBI:mysql:test:localhost", "my_username", "my_passwd",
    {
     PrintError => 1, # warn( ) on errors
     RaiseError => 0, # don't die on error
     AutoCommit => 1, # commit executes immediately
    }
);

For this method to work, you need to make sure that you have built mod_perl with PERL_CHILD_INIT=1 or EVERYTHING=1.

Be warned, though, that if you call connect_on_init( ) and your database is down, Apache children will be delayed at server startup, trying to connect. They won't begin serving requests until either they are connected or the connection attempt fails. Depending on your DBD driver, this can take several minutes!

 

Continue to:

  • prev: 20.2. Improving Performance
  • Table of Contents
  • next: 20.2.2. Improving Speed by Skipping ping( )







TOP
previous page: 20.2. Improving Performance
  
page up: HTML Version of the book
  
next page: 20.2.2. Improving Speed by Skipping ping( )


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com