Open robertrossmann opened 9 years ago
Working with multiple Ldap instances calls for specialized class for this, or at least some static method(s).
Specialized class:
$parallelSearch = new ParallelSearch(Ldap:SCOPE_SUBTREE); //scope must be the same
$parallelSearch->add($ldap1, 'DC=example,DC=com', 'objectClass=user');
$parallelSearch->add($ldap2, 'DC=example,DC=com', 'objectCategory=Person');
$results = $parallelSearch->perform($attributes, $attrsOnly, $sizeLimit, $timeLimit, $deref);
$entries1 = $results[0]->getEntries();
$entries2 = $results[1]->getEntries();
Static methods:
Ldap::addParallelSearch($ldap1, 'DC=example,DC=com', 'objectClass=user');
Ldap::addParallelSearch($ldap2, 'DC=example,DC=com', 'objectCategory=Person');
$results = Ldap::performParallelSearch($attributes, $scope, $attrsOnly, $sizeLimit, $timeLimit, $deref); //possible magic static methods for each scope
$entries1 = $results[0]->getEntries();
$entries2 = $results[1]->getEntries();
PHP allows doing parallel searches. This could greatly enhance application's performance in situations where multiple search requests need to be issued.
Currently, the only way to perform parallel search is to gather the underlying ldap link resources with
Ldap::getResource()
and callingldap_search()
directly. This, however, breaks the purpose of having a testable ldap interface. As such, support for this feature should be added into the library.A proposed API could look like this:
Ldap::parallelSearch()
(or justLdap::parallel()
) with parameter signature identical to that ofLdap::ldapSearch()
Ldap::$parallels
property)Once a call to
Ldap::ldapSearch()
is made (without arguments), a parallel search is executed with the params queued up inLdap::$parallels
and the results are returned in an array. The aforementioned protected property is emptied/reset.Caveats
objectClass
for first search and onlyobjectCategory
for the second search. I filed a PHP bug ages ago, but so far no progress has been made. In the past, I dealt with this by doing a union on the requested attributes, but this is somewhat unintuitive. A better approach would be to change the proposed API to not accept$attributes
parameter in calls toLdap::parallel()
and only accept it once theLdap::ldapSearch()
method is called, i.e.: