Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Persistent DBI connection with mySQL

by dga (Hermit)
on Jul 18, 2003 at 15:26 UTC ( #275638=note: print w/replies, xml ) Need Help??


in reply to Persistent DBI connection with mySQL

As mentioned already, Apache::DBI.

There is also connect_cached() via the standard DBI.

This allows you to select which connections that you want to be persistant (connect_cached)and which you don't (connect).

The DBI keeps a hash of the connection options and reuses the open connection if the options are identical.

I use this on my mod_perl sites, so that if I access a database very rarely, or with unusual options, I can single it out not to persist and yet get all the benefits of the ones that are used frequently, persisting. One example of this is a report which takes a while to run anyway since it's big and thus the connection overhead is not noticable and is only run every once in a while. If I kept the connection around and the child process lasted long enough for another call to the report, the likelihood that the same child would get the request a week from now is remote at best, so a new connection would be made anyway. Thus I go ahead and toss the connection as soon as the page is sent to the user.

There is also prepare_cached but this reqiures some forethought as you are reusung a statement handle and you need to be aware of the effect of context of calling these from different subs for example. This is handy where the query plan takes a while to generate and you need to do the same query frequently.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://275638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-06-15 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (72 votes). Check out past polls.

    Notices?