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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 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