<!--- keep a list of online users --->
<cfif Session.LoggedIn>
<cfif NOT IsDefined("Application.UsersInfo")>
<cflock timeout="15" scope="APPLICATION" type="EXCLUSIVE">
<cfif NOT IsDefined("Application.UsersInfo")>
<cfset Application.UsersInfo = StructNew()>
</cfif>
</cflock>
</cfif>
<cfif NOT StructKeyExists(Application.UsersInfo, session.UserID)>
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
<cfif NOT StructKeyExists(Application.UsersInfo, session.UserID)>
<cfset StructInsert(Application.UsersInfo, session.UserID, now())>
</cfif>
</cflock>
</cfif>
<cfloop collection="#Application.UsersInfo#" item="itmUser">
<cflock name="session_lock_#itmUser#" timeout="15">
<cfif StructKeyExists(Application.UsersInfo, itmUser)>
<cfif DateDiff("n", Application.UsersInfo[itmUser], Now()) GT 15>
<cfset StructDelete(Application.UsersInfo, itmUser)>
</cfif>
</cfif>
</cflock>
</cfloop>
</cfif>
My question involves the StructDelete portion of the code, namely:
<cfloop collection="#Application.UsersInfo#" item="itmUser">
<cflock name="session_lock_#itmUser#" timeout="15">
<cfif StructKeyExists(Application.UsersInfo, itmUser)>
<cfif DateDiff("n", Application.UsersInfo[itmUser], Now()) GT 15>
<cfset StructDelete(Application.UsersInfo, itmUser)>
</cfif>
</cfif>
</cflock>
</cfloop>
I have this script in the application.cfm file, which means this loop is activated with every single click. Sure, it isn't that much load, but I don't see any reason why this should kick in so often. So I cut it out of the application.cfm file and created a separate file, called cleanup_online_users.cfm. Then I used Scheduled Tasks to schedule this snippet of code -- and it doesn't work. It's very strange -- if I run it manually, it doesn't work, either. However, if I manually run it AND THEN force a refresh, it works. I was wondering if CF was somehow caching this page, so I changed the page to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>cleanup</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</head>
<body>
<!--- cleanup_online_users.cfm --->
<cfloop collection="#Application.UsersInfo#" item="itmUser">
<cflock name="session_lock_#itmUser#" timeout="15">
<cfif StructKeyExists(Application.UsersInfo, itmUser)>
<cfif DateDiff("n", Application.UsersInfo[itmUser], Now()) GT 15>
<cfset StructDelete(Application.UsersInfo, itmUser)>
</cfif>
</cfif>
</cflock>
</cfloop>
</body>
</html>
Still doesn't work. The only way to make it work is if I load it manually and then refresh. What am I doing wrong?
I'm running Win2K & CFMX 6.1.
- Sung
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

