Code

Added max query time for search / ls
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Apr 2006 04:53:56 +0000 (04:53 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Apr 2006 04:53:56 +0000 (04:53 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3153 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ldap.inc

index 677f7f459025e90075dbff282d84a4f2e14e357e..3c1edad0ddbd557f7809a8afaba8c5d822509446 100644 (file)
@@ -30,16 +30,24 @@ class LDAP{
   var $hostname = "";
   var $follow_referral = FALSE;
   var $referrals= array();
-
+  var $max_ldap_query_time = 0;   // 0, empty or negative values will disable this check 
 
   function LDAP($binddn,$bindpw, $hostname, $follow_referral= FALSE, $tls= FALSE)
   {
+    global $config;
     $this->follow_referral= $follow_referral;
     $this->tls=$tls;
     $this->binddn=$this->convert($binddn);
 
     $this->bindpw=$bindpw;
     $this->hostname=$hostname;
+
+    /* Check if MAX_LDAP_QUERY_TIME is defined */ 
+    if(isset($config->data['MAIN']['MAX_LDAP_QUERY_TIME'])){
+      $str = $config->data['MAIN']['MAX_LDAP_QUERY_TIME'];
+      $this->max_ldap_query_time = (float)($str);
+    }
+
     $this->connect();
   }
 
@@ -171,12 +179,23 @@ class LDAP{
   {
     if($this->hascon){
       if ($this->reconnect) $this->connect();
+
+      $start = microtime();
+   
       $this->clearResult();
       $this->sr = @ldap_search($this->cid, $this->fix($this->basedn), $filter, $attrs);
       $this->error = @ldap_error($this->cid);
       $this->resetResult();
       $this->hasres=true;
-  
+   
+      /* Check if query took longer as specified in max_ldap_query_time */
+      if($this->max_ldap_query_time){
+        $diff = get_MicroTimeDiff($start,microtime());
+        if($diff > $this->max_ldap_query_time){
+          print_red(sprintf(_("The ldapserver is answering very slow (%.2f), this may be responsible for performance breakdowns."),$diff)) ;
+        }
+      }
+
       return($this->sr);
     }else{
       $this->error = "Could not connect to LDAP server";
@@ -193,10 +212,22 @@ class LDAP{
         $basedn = $this->basedn;
       else
         $basedn= $this->convert($basedn);
+  
+      $start = microtime();
+
       $this->sr = @ldap_list($this->cid, $this->fix($basedn), $filter,$attrs);
       $this->error = @ldap_error($this->cid);
       $this->resetResult();
       $this->hasres=true;
+
+       /* Check if query took longer as specified in max_ldap_query_time */
+      if($this->max_ldap_query_time){
+        $diff = get_MicroTimeDiff($start,microtime());
+        if($diff > $this->max_ldap_query_time){
+          print_red(sprintf(_("The ldapserver is answering very slow (%.2f), this may be responsible for performance breakdowns."),$diff)) ;
+        }
+      }
+
       return($this->sr);
     }else{
       $this->error = "Could not connect to LDAP server";