Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found