Preformance check - online brugere!
Hej!Jeg har følgende kodestump til at tælle aktuelle brugere på siden lige nu, men er usikker på om det er noget som vil kræve unødigt meget for serveren.
Nogen der kan be- eller afkræfte dette?
P.S. Brugerne tælles via IP-adresse i stedet for session, da tallet således bliver mere nøjagtigt.
Kode: (må bruges frit!)
<%
'subroutine to add new user or update old user's timestamp
sub addCurrentUser
dim strCurrentUserList
dim intStart
dim intEnd
dim strUserStamp
Dim VarIp
VarIp = Request.ServerVariables("REMOTE_ADDR")
strCurrentUserList=application("strCurrentUserList")
intStart=instr(1 , strCurrentUserList , VarIp)
if intStart>0 then
application.lock
intEnd=instr(intStart , strCurrentUserList , "$")
strUserStamp=mid(strCurrentUserList , intStart , intEnd-intStart)
strCurrentUserList = replace(strCurrentUserList , strUserStamp , VarIp & ":" & now())
application("strCurrentUserList")=strCurrentUserList
application.unlock
else
application.lock
application("intTotalCurrentUsers")=cint(application("intTotalCurrentUsers")) + 1
application("strCurrentUserList")=strCurrentUserList & VarIP & ":" & now() & "$"
application.unlock
end if
end sub
'subroutine to remove inactive users from the count
sub clearOldUser
dim strCurrentUserList
dim intRunTime
dim intUserTimeOut
dim arrCurrentUserList
dim intTotalCurrentUsers
dim n
intUserTimeOut=10
intRunTime=1
strCurrentUserList = application("strCurrentUserList")
if strCurrentUserList="" then
exit sub
end if
if datediff("n" , application("intLastRunTime") , now())>intRunTime then
application.lock
application("intLastRunTime")=now()
application.unlock
intTotalCurrentUsers=0
strCurrentUserList = application("strCurrentUserList")
strCurrentUserList = left(strCurrentUserList , len(strCurrentUserList)-1)
arrCurrentUserList = split(strCurrentUserList , "$")
for n =0 to ubound(arrCurrentUserList)
if datediff("n", mid(arrCurrentUserList(n) , instr(1, arrCurrentUserList(n), ":") + 1 , len(arrCurrentUserList(n))), Now()) > intUserTimeOut then
arrCurrentUserList(n)="old"
else
intTotalCurrentUsers=intTotalCurrentUsers+1
end if
next
strCurrentUserList=join(arrCurrentUserList , "$") & "$"
strCurrentUserList=replace(strCurrentUserList , "old$" , "")
application.lock
application("strCurrentUserList")=strCurrentUserList
application("intTotalCurrentUsers")=intTotalCurrentUsers
application.unlock
end if
end sub
addCurrentUser
clearOldUser
%>
<%= application("intTotalCurrentUsers")%>
