Avatar billede hifi4all Nybegynder
14. oktober 2005 - 13:12 Der er 1 løsning

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")%>
Avatar billede hifi4all Nybegynder
06. januar 2006 - 17:32 #1
lukket :(
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester