From: Markus W. <mw...@fa...> - 2002-01-12 20:41:27
|
Hi, i think my ResourcePool module does the trick you are seraching for. there is something callse LoadBalacer which can handle failover, but since the basic idea of the ResourcePool is to be generic, it doesn't work transperently. anyway using the ResourcePool your code would look like this: ---<snip>--- use ResourcePool; use ResourcePool::Factory::Net::LDAP; my $factory = ResourcePool::Factory::Net::LDAP("ldap.fatalmind.com" [ dn => "cn=Manager,dc=fatalmind,dc=com", password => "secret" ] ); my $pool = ResourcePool->new($factory); my $ldaph; while (there_is_work) { $ldaph = $pool->get(); # here is the trick # do shit $pool->free($ldaph); } ---<snap>--- so basically you have a container which creates connections if you need them BUT it also checks if the connections are valid before it hands out the handle. the get() method checks the validity of the connection by bind()-ing again. if this works it returns the handle, otherwise it tries to open a new connection, if this also fails it return undef. the package also includes a LoadBalancer module which is able handle failover to other servers. you can find this modules on CPAN or on my homepage http://www.fatalmind.com/programs/ResourcePool/ -markus > Hi, > > I'm trying to get a perl script I've written to stay connected to > my LDAP server between searches... > This works great, until I take the LDAP server offline for a moment... > What happens is that I the next $ldaps->search comes around, which > results in a "Broken Pipe" and the program exiting. > I'd obviously prefer if, before that point, a check could be done, and > if the connection was dropped, try reconnecting. > > So basically, is it possible to have a persistent ldap connection & > bind that will re-connect if disconnected? > > I was unable to find anything in the archives with a clear solution... > > Thanks, > > Eric Parusel - - - - - - - - - - - - - Markus Winand e-mail: mw...@fa... phone: +43-664-221 6348 web: www.fatalmind.com |