我需要遍历LDAP基础上的所有条目。实际上,LDAP服务器每次搜索限制为500个条目。我正在使用PHP 5.6。
我找到了使用ldap_control_paged_result和ldap_control_paged_result_response的可能解决方案,并且只实现了一个简单的测试脚本:
(...)
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 != '');
但我仍然无法检索超过500个条目,这是输出:
(...)
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)
(...)
我错过了什么吗?