How long does it normally take this script to run? I've never run into a database connection timeout situation before. If you can, briefly describe what this script did *before* you changed it to connect every time you call a function - did it connect, then do lots of database stuff, and then close the connection, or are there gaps of time in between when there is no database interaction?
Seems like an enormous waste of time to connect (and disconnect) to the database in every function!! There's got to be a way around that. The 'ping' solution is a step in the right direction, and that may be the best solution. Ping is designed to be very fast and efficient - you should only need to re-connect if ping is unsuccessful.
Also, as someone else already pointed out, it's very inefficient and wasteful to put the db connection parameters in more than one place. You should create a myConnect (or whatever) subroutine and in that subroutine do your dbi connect and return the resulting database handle ($dbh) to the caller. In that subroutine put the connection parameters so that you have them just in one place. That way if your connection parameters change, you only need to change them in one place.
HTH.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.