您可以抓取网络数据包捕获(例如 Wireshark)——因为您使用的是明文 LDAP,所以它是可读的。您将在数据包上看到高分辨率的时间戳,并且可以识别延迟发生的位置。您还可以在代码中打破身份验证过程的不同组件的时间,以更好地了解 什么 需要很长时间(示例如下)。
是否存在潜在的网络问题——例如大量重新传输的数据包?
在使用 SSL 的情况下,协商 SSL 会话可能需要很长时间。
使用负载平衡 VIP(如果存在)和每个目录服务器是否会得到不同的结果?可能存在性能不佳的特定服务器。我还遇到了负载均衡器配置,这些配置引入了大量延迟(VIP 很慢,每个目录服务器都很好),并且能够通过提供良好的统计数据来吸引网络团队。
<?php
// Turn off all error reporting
error_reporting(0);
function getLDAPBindTime($strHostname, $iPort, $strDescription){
$ldaprdn = 'uid=SystemAccount,ou=SystemIDs,o=Company';
$ldappass = 'SystemAccountPassword';
$ldaproot = 'ou=SystemIDs,o=Company';
$iUserObjectClass = 'inetOrgPerson';
echo "<tr><td>$strHostname</td><td>$strDescription</td>";
$strConnectString = "ldaps://" . $strHostname . ":" . $iPort;
$totaltime = microtime();
$totaltime = explode(' ', $totaltime);
$totaltime = $totaltime[1] + $totaltime[0];
$totalbegintime = $totaltime;
$ds = ldap_connect($strConnectString) or $tempflag = 1;
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or $ldaperrflag = 1;
$totaltime = microtime();
$totaltime = explode(' ', $totaltime);
$totaltime = $totaltime[1] + $totaltime[0];
$bindbegintime = $totaltime;
if ($ds) {
$scriteria="(&(objectClass=$iUserObjectClass))";
$ldapbind = ldap_bind($ds, $ldaprdn, $ldappass) or $otherflag =1;
$resultcode = ldap_errno($ds);
if($resultcode != 0){
$ldaperrflag = 2;
}
else{
$totaltime = microtime();
$totaltime = explode(' ', $totaltime);
$totaltime = $totaltime[1] + $totaltime[0];
$querybegintime = $totaltime;
$sr=ldap_search($ds,$ldaproot,$scriteria);
$info = ldap_get_entries($ds, $sr);
if($info["count"] > 3){
$ldaperrflag = 0;
}
else{
$ldaperrflag = $ldaperrflag + 5;
}
}
ldap_close($ds);
}
$totaltime = microtime();
$totaltime = explode(" ", $totaltime);
$totaltime = $totaltime[1] + $totaltime[0];
$totalendtime = $totaltime;
$totaltime = ($totalendtime - $totalbegintime)*1000;
$totalconnect = ($bindbegintime - $totalbegintime)*1000;
$totalbind = ($querybegintime - $bindbegintime)*1000;
$totalquery = ($totalendtime - $querybegintime)*1000;
$totaltime = round($totaltime,2);
$totalconnect = round($totalconnect,2);
$totalbind = round($totalbind,2);
$totalquery = round($totalquery,2);
if($ldaperrflag == 2 || $ldaperrflag == 6 || $ldaperrflag == 3 || $ldaperrflag == 7 || $ldaperrflag == 8 || $ldaperrflag == 1){
echo "<td><font color=red>Failed to connect or bind to server</font></td><td>n/a</td><td>n/a</td><td>n/a</td><td>$totaltime ms</td>";
}
if($ldaperrflag == 5){
echo "<td><font color=red>Bind successful, search failed</font></td><td>$totalconnect ms</td><td>$totalbind ms</td><td>$totalquery ms</td><td>$totaltime ms</td>";
}
if($ldaperrflag == 0){
echo "<td><font color=green>Bind and search successful</font></td><td>$totalconnect ms</td><td>$totalbind ms</td><td>$totalquery ms</td><td>$totaltime ms</td>";
}
echo "</tr>";
}
set_time_limit(300);
echo "<head><title>iPlanet LDAP Service Status</title></head><body>";
echo "<h3>iPlanet LDAP Service Status</h3>";
echo "<table cellpadding=1 border=1>";
echo "<tr><td><b>Server</b></td><td><b>Description</b></td><td><b>Status</b></td><td><b>Connect Time</b></td><td><b>Bind Time</b></td><td><b>Query Time</b></td><td><b>Total Time Elapsed</b></td></tr>";
getLDAPBindTime("VIPName.company.gTLD", 636, "ldap.company.gTLD VIP");
getLDAPBindTime("hostname1.company.gTLD", 1636, "LDAP Master Server");
getLDAPBindTime("hostname2.company.gTLD", 1636, "LDAP Master Server");
echo "</table><P>";
echo "</table><p>";
putenv('TZ=GMT');
echo "<font size=-1><P><i>Current time in GMT is ";
echo date("d M Y H:i");
echo '</i><P><a href="https://site.company.gTLD:1977/svcstatus/">Back</a></font>';
echo "</body>";
?>