PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: David Hajoglou <hojo at greenland dot i-tel dot com>
Subject: Sybperl, child processes and persistance
Date: Mar 19 1999 11:06PM

Michael,
	A few weeks ago you sent me this code(below) for persistant
database handels.  And, it is working with only one catch. the handel is
staying alive in the child process, but each request is going to the next
process and opening a new connection.  Is there a way to somehow document
the child process and use the same one for each request?

David Hajoglou



 On Thu, 11 Feb 1999, Michael Peppler wrote:



> 
> 
> package Apache::Sybase::DBlib;
> 
> 
> use Sybase::DBlib;
> use strict;
> 
> @Apache::Sybase::DBlib::ISA = qw(Sybase::DBlib);
> 
> my %Connected;
> 
> *Apache::Sybase::DBlib::new = \&connect;
> 
> sub connect {
>     my($self, @args) = @_;
>     foreach (@args) {
> 	$_ = '' unless $_;
>     }
>     my($Uid, $Pwd, $Srv) = @args;
>     my $idx = join(":", @args);
> 
> #    foreach (keys(%Connected)) {
> #	print STDERR "Connected: $_\n";
> #    }
>     if($Connected{$idx} && ping($Connected{$idx})) {
> 	warn "Already connected to $idx" if $main::DEBUG;
> 	return bless($Connected{$idx}, "Apache::Sybase::DBlib");
>     }
>     print STDERR "connecting to $idx from $$\n" if $main::DEBUG;
>     my $dbh = Sybase::DBlib->dblogin($Uid, $Pwd, $Srv, "Apache-$$");
> 
>     if(!$dbh) {
> 	return undef;
>     }
> 
>     $Connected{$idx} = $dbh;
> 
> #    print STDERR "$Connected{$idx}\n";
> 
>     bless($Connected{$idx}, "Apache::Sybase::DBlib");
> }
> 
> sub DESTROY {
>     print STDERR "DESTROY called!!\n";
>     1;
> }
> 
> # Yuck!
> sub ping {
>     my $dbh = shift;
> 
>     my $ret = $dbh->sql("select getdate()");
> 
>     $ret;
> }
> 
> 1;
>