Determining the ColdFusion Default, and Max, Session timeouts with code

This post is more than 2 years old.

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 admin = createObject("component", "CFIDE.adminapi.administrator")> <cfset admin.login("admin")> <cfset runtime = createObject("component", "CFIDE.adminapi.runtime")>

<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>

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:

<!--- 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>

<p/> <cfoutput> Total minutes for default sessionTimeout is #totalMinutes#. </cfoutput>

This returns 20 on my server.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Peter Schmidt posted on 10/13/2011 at 9:37 PM

I try to execute the code you provided and got

The current user is not authorized to invoke this method.

Any Ideas??

Comment 2 by Geoff B posted on 10/13/2011 at 9:47 PM

Peter, make sure you replace "admin" with your actual cfadmin password.

Comment 3 by Peter Schmidt posted on 10/13/2011 at 10:14 PM

Thank you

Comment 4 by Mark Landmann posted on 10/14/2011 at 1:30 AM

Where are all these internal APIs defined. I would like to access one specifically that turns OFF caching if it is on.

Comment 5 by Raymond Camden posted on 10/14/2011 at 1:58 AM

This isn't an internal API. It's a documented feature. Go to /CFIDE/adminapi and you can see the CFCs there.

The official docs are here:

Comment 6 by Mike Henke posted on 10/14/2011 at 2:26 AM

@cfaddict mentioned also application.getApplicationSettings() will return a struct w/ all of your application settings or new Application() - new instance.

And this is the link I used to see all the method documentation for the cfc's

Comment 7 by Sooraj posted on 10/14/2011 at 10:46 AM

Hi Ray,

How do we implement the same for Railo?


Comment 8 by Raymond Camden posted on 10/14/2011 at 2:34 PM

I don't use Railo.