1

I'm using ldap_connect to work with an LDAP server from an PHP application, which works fine. Now I need to set timeouts, so that an request will be canceled if it runs to long. For this I set the following options with the following lines of code:

$ldapconn = ldap_connect($ldap['host'], $ldap['port'])
            or myExClass::throwException("unable to connect");
echo LDAP_OPT_TIMELIMIT;
ldap_set_option ($ldapconn, LDAP_OPT_TIMELIMIT,1);
ldap_set_option ($ldapconn, LDAP_OPT_NETWORK_TIMEOUT,1);
echo LDAP_OPT_TIMELIMIT;

The echo are inserted for debugging. In this example I found out, that the option LDAP_OPT_TIMELIMIT is unchanged 4. Before and after ldap_set_option.

Why that option is not changed? What could be the reason? By the way: the return code of ldap_set_optionis 1 in both cases.

4

1 回答 1

3

LDAP_OPT_TIMELIMIT is a flag used to tell ldap_set_option() which option to set—its value should never change. The 1 in ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 1); is the value you're setting for LDAP_OPT_TIMELIMIT.

Since your calls to ldap_set_option are returning TRUE it sounds like they're working correctly. You can verify your setting with ldap_get_option():

if( ldap_get_option($ldapconn, LDAP_OPT_TIMELIMIT, $retVal) ) {
    echo $retVal;
} else {
    echo "Uh oh. Couldn't retrieve value for LDAP_OPT_TIMELIMIT.";
}
于 2013-08-28T11:48:50.390 回答