我有大约12个PHP函数,每个函数调用$ ldap_connect,它使用ldap_bind()
所以 - 这是否意味着当我调用所有函数时,我的ldap服务器会产生12个ldap绑定?
如果是这样 - 应该何时使用ldap_unbind()函数?我试过搜索这个,但没有任何结果,我似乎发现每次都“解开”,但这并不是特定的。这是否意味着在我返回数据之前在所有12个函数中放置一个unbind,或者在我的logout页面上取消绑定,我还会在其中执行session_destroy()?
由于
编辑:代码
const int MAX_PATH = 260;
[StructLayout(LayoutKind.Sequential)]
public struct RASENTRY
{
public int dwSize;
public int dwfOptions;
public int dwCountryID;
public int dwCountryCode;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxAreaCode+1)]
public string szAreaCode;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxPhoneNumber+1)]
public string szLocalPhoneNumber;
public int dwAlternateOffset;
public RASIPADDR ipaddr;
public RASIPADDR ipaddrDns;
public RASIPADDR ipaddrDnsAlt;
public RASIPADDR ipaddrWins;
public RASIPADDR ipaddrWinsAlt;
public int dwFrameSize;
public int dwfNetProtocols;
public int dwFramingProtocol;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) MAX_PATH)]
public string szScript;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) MAX_PATH)]
public string szAutodialDll;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) MAX_PATH)]
public string szAutodialFunc;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxDeviceType + 1)]
public string szDeviceType;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxDeviceName + 1)]
public string szDeviceName;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxPadType + 1)]
public string szX25PadType;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxX25Address + 1)]
public string szX25Address;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxFacilities + 1)]
public string szX25Facilities;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxUserData + 1)]
public string szX25UserData;
public int dwChannels;
public int dwReserved1;
public int dwReserved2;
public int dwSubEntries;
public int dwDialMode;
public int dwDialExtraPercent;
public int dwDialExtraSampleSeconds;
public int dwHangUpExtraPercent;
public int dwHangUpExtraSampleSeconds;
public int dwIdleDisconnectSeconds;
public int dwType;
public int dwEncryptionType;
public int dwCustomAuthKey;
public Guid guidId;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) MAX_PATH)]
public string szCustomDialDll;
public int dwVpnStrategy;
public int dwfOptions2;
public int dwfOptions3;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxDnsSuffix)]
public string szDnsSuffix;
public int dwTcpWindowSize;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) MAX_PATH)]
public string szPrerequisitePbk;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =
(int) RasFieldSizeConstants.RAS_MaxEntryName)]
public string szPrerequisiteEntry;
public int dwRedialCount;
public int dwRedialPause;
RASIPV6ADDR ipv6addrDns;
RASIPV6ADDR ipv6addrDnsAlt;
public int dwIPv4InterfaceMetric;
public int dwIPv6InterfaceMetric;
RASIPV6ADDR ipv6addr;
public int dwIPv6PrefixLength;
public int dwNetworkOutageTime;
}
public enum RasFieldSizeConstants
{
RAS_MaxDeviceType = 16,
RAS_MaxPhoneNumber = 128,
RAS_MaxIpAddress = 15,
RAS_MaxIpxAddress = 21,
RAS_MaxEntryName = 256,
RAS_MaxDeviceName = 128,
RAS_MaxCallbackNumber = RAS_MaxPhoneNumber,
RAS_MaxAreaCode = 10,
RAS_MaxPadType = 32,
RAS_MaxX25Address = 200,
RAS_MaxFacilities = 200,
RAS_MaxUserData = 200,
RAS_MaxReplyMessage = 1024,
RAS_MaxDnsSuffix = 256,
UNLEN = 256,
PWLEN = 256,
DNLEN = 15
}
public struct RASIPADDR {
byte a;
byte b;
byte c;
byte d;
}
public struct RASIPV6ADDR
{
byte a;
byte b;
byte c;
byte d;
byte e;
byte f;
}
然后我使用$ ldap_conn = create_ldap_connection($ user,$ pass);
所以,我的两个职能是:
function create_ldap_connection($username, $password) {
$ip = "MY LDAP SERVER";
$port = 389;
/* Binding */
$username = "DOMAIN\\" . $username;
$ldap_conn = ldap_connect($ip, $port) or die("Sorry! Could not connect to LDAP server ($ip)");
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Couldn't set option version 3");
$starttls = ldap_start_tls($ldap_conn) or die ("Couldn't start secure TLS connection");
$result = ldap_bind($ldap_conn, $username, $password) or die("Error: Couldn't bind to server using provided credentials!");
if($result) {
return $ldap_conn;
} else {
die("
Error: Couldn't bind to server with supplied credentials!");
}
}
答案 0 :(得分:1)
一旦绑定了连接,该连接上的先前绑定就是“未绑定”,并替换为当前绑定。因此,如果使用相同的连接,则无需使用unbind 12次。
但是当你连接和绑定12次很有可能你有12个并发连接到LDAP服务器,这可能不是你想要的。
所以也许您应该重新考虑函数的设置以调用ldap_connect
(和ldap_bind
)一次,然后使用该连接12次,而不是创建该连接12次。这可能会减少开销。
一个很好的例子是这样的:
$con = ldap_connect([$params]);
ldap_bind($con, [remaining params]);
ldap_[otherfunc]($con, [remaining params]);
一个不好的例子是这样的:
function connect() {
$con = ldap_connect([params]);
ldap_bind($con, [remaining params]);
return $con;
}
ldap_[otehrfunc](conncet(), [remaining params]);
这将在每次调用connect()
时创建一个新的ldap-connection。
要将其更改为“好”示例,您应该按如下方式更改,以多次使用连接:
$con = connect();
ldap_[otherfunc]($con, [remaining params]);