>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

viewing sessions on your server across all applications

Have you ever wanted to know how many sessions are running on your server across ALL applications, then this code snippet should help. A big thanks to Russ AKA snake for helping on this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <title>session tracker</title>
</head>

<body>
<cfapplication name="">
<cfset request.overallTotal = 0 />
<cfloop collection="#application#" item="applicationName">

   <cfscript>
   sessiontrackerObj= createObject("java","coldfusion.runtime.SessionTracker");
   activesessions = sessiontrackerObj.getSessionCollection('#applicationName#');
   nosessions=ListLen(structkeyList(activeSessions));
   </cfscript>
   <cfif nosessions>
      <cfoutput>
         <h3>Total Sessions for #applicationName#: #nosessions#</h3>
      </cfoutput>
   <cfif structKeyExists(url,"showSessions")><cfdump var="#activesessions#"></cfif>
   </cfif>
   <cfset request.overallTotal = request.overallTotal + nosessions />   

</cfloop>
<h3 style="position:absolute; top:0; right:0; width:200px;">OVERALL SESSIONS:

<cfoutput>#request.overallTotal#</cfoutput></h3>

</body>
</html>


 
Comments
Tariq Ahmed's Gravatar Holy cow, I was actually wondering how to do this yesterday. You just saved me a ton of time. Thanks. :)
# Posted By Tariq Ahmed | 04/05/06 16:15 | Report abusive comment
Matt Ford's Gravatar Holy cow is right. Yet another reason to restrict the ability to call createObject("java") on shared hosting servers!
# Posted By Matt Ford | 04/05/06 18:09 | Report abusive comment
Douglas Knudsen's Gravatar a bit old news, but yes. Keep messing with it and you will discover that you can actually drill into each individual session and look at the variables stuck there.

DK
# Posted By Douglas Knudsen | 04/05/06 18:52 | Report abusive comment
-'s Gravatar I think that Snake stole it off someone else.
# Posted By - | 05/05/06 13:43 | Report abusive comment
Nick Tong's Gravatar Actually his does credit Alex from pixl8.co.uk on his blog, as should I - thanks Alex.
# Posted By Nick Tong | 05/05/06 14:47 | Report abusive comment
theofficenews's Gravatar most popular trends on one site
http://theofficenews.com
# Posted By theofficenews | 09/04/08 07:55 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.