Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: max DBPROCESS problem
Date: Mar 12 2001 11:59PM

jimmy mcdonald writes:
 > >If each apache httpd process can have up to 50 open connections then
 > >your DB server will have to be configured to handle a *lot* of
 > >connections, and that's just wasting space.
 > >
 > >(unless each script connects to a different database server, of course)
 > i guess i dont understand how this is different.
 > from what i understand my perl script opens a connection
 > to the database and leaves it open. after 25 scripts
 > have done this, i get errors.

OK - so you have a problem with the fact that your scripts don't close
the connections.

 > if i use the method you
 > just posted, wouldnt each script still take on a persistent
 > connection of its own?
 > or, in other words, how does the code you suggested share the
 > connections?

The My::Sybase::connect() routine returns the connection if it already
exists, or creates a new connection otherwise.

Consider this:

package My::Sybase;

my $dbh;    # static variable in this module/file

sub connect {
    return $dbh if $dbh;   # return $dbh if $dbh has already
                           # been initialized.

    # if we get to here then $dbh has not been initialized yet for
    # this httpd process, so connect:

    $dbh = new Sybase::DBlib ... ...;




So what happens is that the first script that calls
My::Sybase::connect() for this httpd process will generate a new
connection. Each subsequent script will re-use that same connection. 

Now you should be aware that the code shown is very minimal, and
should be enhanced with proper error checking. But it should give you
an idea on how you can keep a connection (or any other variable or
resource) available between CGI scripts running on the same httpd
child process.

 > im not writing the scripts, im just trying to help the people who
 > are to avoid running out of connections, so i apologize for
 > not understanding the way that most people on this list would.
 > my job is to keep the systems up and running and this is causing
 > problems such as filling error logs and causing end user complaints
 > which eventually land on my desk.

I understand. Hopefully this is a little clearer now (if not - forward
this email to your developers...)

Michael Peppler - Data Migrations Inc. - -
International Sybase User Group -
Sybase on Linux mailing list: