One thing you may wish to do is look at using a callback routine with your search. If I am reading your code correctly, you are not doing so yet. That being the case, the search waits for all the results to be returned (which can be quite some time, if there are a large number of records in the LDAP data store you are querying), whereas if a callback routine is used, each record is processed as found.
The code below is part of a test routine I used a while back (edited appropriately, with appologies for any errors that may have been edited in), which might give you an idea on using a callback routine. (The LDAP modules' documentation were quite helpful for me when I had to do something with it.)
#!/usr/bin/perl -w use Net::LDAP qw(:all); use Net::LDAP::Entry; use Net::LDAP::LDIF; use Net::LDAP::Util qw(ldap_error_text); use strict; $| = 1; my $ldap_server = "your.ldap.server.here"; my $basedn = "your.base.dn.here"; my $binddn = "your.bind.dn.here"; my $password = "your.ldap.password.here"; my $ldap = Net::LDAP->new($ldap_server) or die ( $@ . "\n" ); my $msg = $ldap->bind( $binddn, password => $password ); my $scope = "base"; my $filter = "(objectClass=*)"; my $searchobj = $ldap->search( base => $basedn, filter => $filter, callback => \&process ); die ( "Bad search: " . ldap_error_text( $searchobj->code() ) ) if ( $searchobj->code() ); sub process { my $mesg = shift; my $obj = shift; if ( !$obj ) { # Search complete } else { my $dn = $obj->dn(); { my @parts = (); print( 'dn: ', $dn, "\n" ); foreach my $attr ( sort( { lc($a) cmp lc($b) } $obj->attributes ) ) { print( join ( ': ', $attr, $obj->get_value($attr) ), "\n" ); } print( "\n" ); } $mesg->pop_entry(); } }
In reply to Re: LDAP Search Script runs slow
by atcroft
in thread LDAP Search Script runs slow
by bionicle32
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |