I generate a directory of people for my society with pictures etc. like a social media. There are like 1000+ users in the LDAP and it takes so long to perform the research which permits to get all users on screen.
It's exactly this part which takes between 4 and 7 seconds to perform a research:
do {
ldap_control_paged_result($ldap, $pageSize, true, $cookie);
$sr=ldap_search($ldap, $dn, $filter, $justthese);
$info = ldap_get_entries($ldap, $sr);
foreach ($info as $in) {
if(isset($in[$GLOBALS['nom']][0])){
$array[0][$inc]=$in[$GLOBALS['nom']][0];
$array[1][$inc]=$in[$GLOBALS['prenom']][0];
$inc++;
}
}
$test++;
ldap_control_paged_result_response($ldap, $sr, $cookie);
} while($cookie !== null && $cookie != '');
I don't know how to optimized it, 5 seconds to generate a page which has a limit of 24 users per page is not possible..
It's not a server side problem because when I execute this research with exactly same filters, same dn USING Apache Directory Studio it takes less than 1 second...
As @LudovicPoitou said in his comment, you loop through all your users in the directory.
For each 24 user in ONE page you display in your web app, your request the entire directory.
I guess from your question that$pageSize
is equal to 24, so what you do is retrieve every users of your directory with page of 24 users per requests.
Then for 1000 entries you make 42+ requests to retrieve 1000+ users to display only 24 of them on each page of your app.
You should requests all these users by page of said 1000 users only one time and make the pagination client side with the complete set of users.
This is a misunderstanding of the use of page result, it is not a pagination result where you want result 0 to 24 and next request is result 25 to 49, etc. (At least not in your web app configuration with php because you are not in a stateful connection with the directory where you do the next search with the cookie on user input)
EDIT :
To illustrate what I mean by not stateful
. When the PHP script end its execution, every variable are destroyed, and so the connection made to the LDAP server. Then the cookie attached to the paged control is not usable anymore as it is linked to the search request made. Than the diagram is like :
STATEFUL
CLIENT BACKEND LDAP
+ + +
| REQUEST page1 | |
| +---------------> | CONNECT + BIND |
| | +--------+------> |
| | SEARCH PAGE 1 |
| | +---------------> |
| | RESPONSE |
| RESPONSE | <---------------+ |
| <---------------+ | |
| | |
| REQUEST page 2 | |
| +---------------> | SEARCH PAGE 2 |
| | +---------------> |
| | RESPONSE |
| RESPONSE | <---------------+ |
| <---------------+ | |
| | DISCONNECT |
| | +---------------> |
| | |
| | |
+ + +
STATELESS
CLIENT PHP LDAP
+ + +
| REQUEST page1 | |
| +---------------> | CONNECT + BIND |
| | +--------+------> |
| | SEARCH ALL PAGES |
| | +---------------> |
| | RESPONSE |
| | <---------------+ |
| | DISCONNECT |
| RESPONSE | +---------------> |
| <---------------+ | |
+ + +