How do you determine the current server's default and max session timeouts via code? This question came up on Twitter today and I thought I'd whip up a quick example. The answer is relatively simple - make use of the Admin API. Here's a quick example.
<cfset sessionDefaultTimeout = runtime.getScopeProperty("sessionScopeTimeout")>
<cfset sessionMaxTimeout = runtime.getScopeProperty("sessionScopeMaxTimeout")> <cfoutput>
The default timeout for sessions is #sessionDefaultTimeout# and the max value is #sessionMaxTimeout#.
</cfoutput>
<cfset admin = createObject("component", "CFIDE.adminapi.administrator")>
<cfset admin.login("admin")>
<cfset runtime = createObject("component", "CFIDE.adminapi.runtime")>
This results in (well, on my server anyway):
The default timeout for sessions is 0,0,20,0 and the max value is 2,0,0,0.
Those values are a string where the first number is days, the second is hours, the third is minutes, and the last is seconds. If you need to do math with the numbers, convert it to something real, like minutes:
<p/>
<cfoutput>
Total minutes for default sessionTimeout is #totalMinutes#.
</cfoutput>
<!--- convert to minutes --->
<cfset parts = listToArray(sessionDefaultTimeout)>
<!--- my total --->
<cfset totalMinutes = 0>
<!--- add in days --->
<cfset totalMinutes += 1440 * parts[1]>
<!--- add in hours --->
<cfset totalMinutes += 60 * parts[2]>
<!--- add in minutes --->
<cfset totalMinutes += parts[3]>
<!--- and seconds --->
<cfset totalMinutes += parts[4]/60>
This returns 20 on my server.