User Queue / Verifying Session Status

Posted on 2004-08-11
Last Modified: 2013-12-24
My ultimate goal is to build a user queue in CF.  I want to allow a certain number of users into a restricted area at a time.  The others will be placed in a queue, informing them they are #n out of m in line, and perhaps eventually try to estimate a wait time.

I have ideas on how to do this, but I need to run a cleanup procedure that removes people who have closed their browsers from the queue.  If I store CFIDs and CFTokens into a structure, can I have a backend routine check to see if these sessions are still active, and remove them from the queue if they have expired?
Question by:TimDg
  • 3
  • 2
LVL 25

Accepted Solution

James Rodgers earned 250 total points
ID: 11776690
here is a code block that will determine the number of users on your site, you could use this and some other code to determine the nummber of usrs in a specific part of teh site by settign a session variable at that application and using teh code block to look for that variable, i use this in an iframe and include it on pages as needed.
yuo can also include a cfif to determine the accessibility of the application

<cfif numUsers GE x>
set queue value
redirect to waiting page
set access value
redirect to app

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

            <meta http-equiv="Refresh" content="20;URL=#RELLOCPATH#users.cfm">
            <link rel="stylesheet" href="#RELLOCPATH#commonFiles/mainstyle.css" type="text/css">


                  <cfsetting enablecfoutputonly="Yes">
                        <cflock timeout="15" scope="APPLICATION" type="EXCLUSIVE">
                              <cfif NOT isDefined("Application.UsersInfo")>
                                    <cfset Application.UsersInfo = StructNew()>
                        <cflock name="#CreateUUID()#" timeout="15" type="EXCLUSIVE">
                              <cfset user_cfid = Evaluate(CFID)>
                              <cfset user_info = Now()>
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                              <cfif NOT StructKeyExists(Application.UsersInfo, user_cfid)>
                                    <cfset temp = StructInsert(Application.UsersInfo, user_cfid, user_info)>
                        <! --- // Ok now, we have to create a way to delete them so they don't stay in the list forever, I'm going to use a 10 minutes difference, to expire the user, remember this code should be in your application.cfm or included in your application.cfm, we are going to use the DateDiff to find out if the structure should be deleted. //--->
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                              <cfloop collection="#Application.UsersInfo#" item="itmUser">
                                    <cfif Evaluate(DateDiff("n", StructFind(Application.UsersInfo, itmUser), Now())) GT 10>
                                          <cfset StructDelete(Application.UsersInfo, itmUser)>
                        <cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
                                    <cfif #StructCount(Application.UsersInfo)# EQ 1>
                                          There is #StructCount(Application.UsersInfo)# user
                                          There are #StructCount(Application.UsersInfo)# users
                                    on the system.
                  <cfsetting enablecfoutputonly="NO">

Author Comment

ID: 11776943
Very nice solution.  Do you have a suggestion on how I can evaluate what position they hold in the queue, so I can admit them to the app when numUsers drops below the threshold?
LVL 25

Expert Comment

by:James Rodgers
ID: 11777109
you could keep an incremental copunter in a session varaible and search through the 'waiting' users to find the lowest value

session.lockedSite.isActive=1/0 1=true,0=false, if true then dont check to see if they are waiting
session.lockesite.accessNumber = 1/*  use an application variable and increment it for each user on the site, use this combined with the isActive to see if they are waiting and their position in the queue

in the iframe above you could add javascript block to advise teh user that they are being redirected to the 'locked' siet

var x=confirm("You are now entering the locked site,\nPress ok to enter or cancel to not enter\npressing cancel will lose your position in the queue")

if(x) window.location.href='lockedpage.cfm'


Author Comment

ID: 11777121
Very nice!  Thank you.
LVL 25

Expert Comment

by:James Rodgers
ID: 11777174
glad I could help

thanks for the points

Featured Post

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now