[turba] Fwd: Re: [nyphp-talk] pagination of search results with ldap

Chuck Hagenbuch chuck at horde.org
Tue Apr 10 15:51:12 UTC 2007


I don't suppose someone has some free time that they'd like to spend  
trying this out with Turba? Could be a huge performance boost if we  
can do all the paging server side...

----- Forwarded message from mba2000 at ioplex.com -----
     Date: Fri, 6 Apr 2007 13:29:04 -0400
     From: Michael B Allen <mba2000 at ioplex.com>
Reply-To: NYPHP Talk <talk at lists.nyphp.org>
  Subject: Re: [nyphp-talk] pagination of search results with ldap
       To: NYPHP Talk <talk at lists.nyphp.org>

On Fri, 6 Apr 2007 09:58:48 -0400
"Alex C" <alexchan.1976 at gmail.com> wrote:

> Hi All,
>
> I would like to know what would be the best way to do paged search
> results for LDAP. Is it even possible to do it similiar to mysql limit
> offset  functionality? Or should i do it via PHP.  However, I do know
> LDAP has pagedSearch control.  i don't know how or if i need to invoke
> it via php.

The below code demonstrates how to use the pagedResultsControl. The PHP
LDAP API is somewhat course but it should work.

Mike

$continue = true;
while ($continue) {
     $paged_control = array(
                         array(
                             'oid' => PAGED_CONTROL_OID,
                             'iscritical' => true,
                             'value' => ldap_ber_printf ('{iO}',
                                                         PAGE_SIZE, $cookie)
                         )
                      );
     if (!ldap_set_option($l, LDAP_OPT_SERVER_CONTROLS, $paged_control)) {
         echo "Not OK: ldap_set_option (controls)\n";
         exit;
     }

     $sr = ldap_search($l, $query, $query_filter, $query_attribs, 0, 0, 0,
                       LDAP_DEREF_NEVER);

     if ($sr === FALSE) {
         echo "Not OK: ldap_search\n";
         exit;
     }

     if (!ldap_parse_result ($l, $sr, &$errcode, &$matcheddn, &$errmsg,
                             &$referrals, &$serverctrls)) {
         echo "Not OK: ldap_parse_result\n";
         exit;
     }

     $paged_control_found = FALSE;
     if (isset($serverctrls)) {
         foreach ($serverctrls as $i) {
             if ($i['oid'] == PAGED_CONTROL_OID) {
                 ldap_ber_scanf($i['value'], '{iO}', &$pagesize, &$cookie);
                 $paged_control_found = TRUE;
                 break;
             }
         }
     }
     if (!$paged_control_found) {
         echo "Not OK: paged control not found in response \n";
         exit;
     }

     // process entries as usual here ...

     if ($cookie == '') {
         $continue = false;
     }
}

--
Michael B Allen
PHP Active Directory Kerberos SSO
http://www.ioplex.com/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php


----- End forwarded message -----


-chuck

-- 
"we are plastered to the windshield of the bus that is time." - Chris


More information about the turba mailing list