nesbert / nobjects

A collection of PHP classes for application development.
0 stars 2 forks source link

Specify maximum network timeout delay for LDAP service #5

Closed andrewfhart closed 11 years ago

andrewfhart commented 11 years ago

The \NObjects\Ldap\Service class does not provide a way to specify the maximum desired amount of time to wait before aborting due to a network timeout (e.g.: the ldap server is unreachable), and the defaults are painfully long (>100 seconds in some cases).

This pull request leverages the LDAP_OPT_NETWORK_TIMEOUT option to allow for programmatic specification of an amount of time to wait before aborting.

Example usage:

$options = array(
    'host' => $settings['host'],
    'defaultUsername' => $settings['username'],
    'defaultPassword' => $settings['password'],
);
$ldapService = new \NObjects\Ldap\Service($options);
$ldapService->setNetworkTimeout(5);  // <-- specify a maximum wait time of 5 seconds

$ldapUser = \NObjects\Ldap\User::authenticate($username, $password, $ldapService);

Tests are included to verify proper behavior of the added getters/setters.