I need to iterate through all entries on a LDAP base. Actually the LDAP server is limited to 500 entries for each search. I am working with PHP 5.6.
I found the possible solution using ldap_control_paged_result and ldap_control_paged_result_response and just implemented one simple test script:
(...)
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$pageSize = 100;
$cookie = '';
$count = 0;
do {
ldap_control_paged_result($conn, $pageSize, true, $cookie);
$result = ldap_search($conn, 'ou=people,dc=ufsf,dc=br', 'uid=*', ['uid', 'name']);
$entries = ldap_get_entries($conn, $result);
foreach ($entries as $entry) {
$count++;
echo $count . ' - ' . $entry['name'][0] . PHP_EOL;
}
ldap_control_paged_result_response($conn, $result, $cookie);
} while($cookie !== null && $cookie != '');
But I still can't retrieve more than 500 entries, This is the output:
(...)
498 - NAME SUPRESSED
499 - NAME SUPRESSED
500 - NAME SUPRESSED
WARNING: ldap_control_paged_result_response(): Result is: Size limit exceeded (4)
WARNING: ldap_control_paged_result_response(): Result is: Size limit exceeded (4)
WARNING: ldap_control_paged_result_response(): Result is: Size limit exceeded (4)
(...)
Am I missing something?