Problem : in some scenarios, for example running a periodic health check on an LDAP / AD server, you may want to set a low timeout so that if a server does not answer LDAP bind requests, a user is notified in a reasonable amount of time. Also, if your PHP code is blocking, a long timeout setting will make your code seem unresponsive. Changing the LDAP connection timeout is not well documented on php.net, so following is a quick example (based on http://grokbase.com/t/php/php-bugs/07a3b9qf7h/42837-new-timeout-parameter-sugest-for-ldap-bind-and-or-ldap-connect):
$ldapconn = ldap_connect(“192.168.1.1”);
ldap_set_option($ldapconn, LDAP_OPT_NETWORK_TIMEOUT, 2); /* 2 second timeout */
2 thoughts on “Nugget Post : Setting LDAP connection timeout for PHP”
Reblogged this on ITechonology.