简体   繁体   中英

LDAP PHP Filter Range?

I was messing around with ldap_search and PHP and I noticed that even though you can limit the amount of results (with the $sizelimit attribute), I am unable to pick a range for that size limit.

Code:

$result = ldap_search($ldapconnect,$ldaptree, "(|(cn=a*)(cn=b*))", $attributes, 0, 100) or die ("Error in search query: ".ldap_error($ldapconnect));

To be more specific. I'm searching an LDAP database that has 60 thousand entries, I can always do an array_slice on the preceding result, but that takes forever considering it still pulls from almost the entire DB. Is there a way to grab the 2nd 100 entries and the third and so on?

Thank you!

Joe

It is not possible to filter from a specific range or offset for a query via LDAP with PHP. You could use paging (see example number 2) and skip certain result sets in the loop of results and only keep certain results. Then what you have what you need abort the paging operation by doing a ldap_control_paged_result($link, 0); . However, this would still be pretty inefficient.

LDAP does support a concept called VLV (Virtual List View) which has more advanced options than the simple paging method. Using VLV you can define an offset and a specific range. There was even a patch submitted to add support for VLV to PHP's LDAP module, but no one took any action on it:

https://bugs.php.net/bug.php?id=62853&edit=2

Beyond that, my best advice would be to make your query more efficient by using an objectClass and objectCategory in the filter. Additionally, require at least 2 or 3 characters in the search filter before it will attempt a query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM