Nugget Post : Setting LDAP connection timeout for PHP

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 */

Advertisement

2 thoughts on “Nugget Post : Setting LDAP connection timeout for PHP

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.