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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.