Skip to main content
Participating Frequently
July 28, 2007
Answered

CFAPPLICATION Help Needed

  • July 28, 2007
  • 5 replies
  • 743 views
Here is the situation: In short I want to set the CFAPPLICATION SESSIONTIMEOUT and CFLOCK TIMEOUT variables dynamically from a variable at top of my application.cfm page.

So basically something like this, which doesnt seem to be working properly:

<cfparam name="sessionTimeout" default="#CreateTimeSpan(0,0,30,0)#" />
<cfapplication name="myappname" sessionmanagement="Yes" setclientcookies="yes" setdomaincookies="no" sessiontimeout="#sessionTimeout#">
<CFERROR TYPE="EXCEPTION" TEMPLATE="access_errors.cfm" EXCEPTION="Any">
<CFLOCK TIMEOUT="#sessionTimeout#" THROWONTIMEOUT="Yes" TYPE="EXCLUSIVE" SCOPE="SESSION">

The purpose is:

1. During my custom "install tools" it will ask the user installing this app how long they wish to set their timeout for, then I intend to write to the application.cfm file.

2. I want the SESSIONTIMEOUT and CFLOCK TIMEOUT to obviously be consistant.

3. On login page I want to display the following code so before login the admin user will know how long of inactivity before it will timeout:

To protect your security you will be asked to re-enter your login details after 30 minutes without any online activity. <cfoutput>#sessionTimeout#</cfoutput>

The issue why I think this is not working properly, is when I do the code above for #sessionTimeout" onto a page, it displays as

0.0208333333333

For the timeout value.

Any suggestions? Will this work? Is my code okay but a different way needed to display "30 minutes"?

Any help on this is greatly appreciated.
    This topic has been closed for replies.
    Correct answer BKBK
    However the issue I am still having is trying to figure out how to display the sessionTimeout to the page formatted automatically. So instead of this 0.0208333333333 it would display '30 minutes'.
    ...
    ...
    Anyways I digress: still trying to figure out how to format the 0.0208333333333 out as "30 minutes" to display on a page.


    <cfset sessiontimeout = createtimespan(0,0,30,0)>
    timeout in days: <cfoutput>#sessiontimeout #</cfoutput><br>
    timeout in minutes: <cfoutput>#sessiontimeout *24*60#</cfoutput>

    5 replies

    Inspiring
    July 29, 2007
    > This is for an admin application, which includes an article manager app I
    > built. So since I do not want it timing out if I take 25 minutes to create an
    > article...which it was before :)...I added the sessiontimeout to my CFAPP tag.
    > And actually for admin applications I should really up it to 1-2 hours :).

    Instead of setting a "hard-coded" best estimate of how long it might take
    to complete a task, simply have a "stay alive" widget on the pages that
    could take a while to finish with (like writing an article). It's easy to
    ping the server with a request every 5min (or some number lower than your
    session time out) with JS. This will have the effect of keeping the
    session active for as long as the user is sitting on that page.

    --
    Adam
    bhakalaAuthor
    Participating Frequently
    July 28, 2007
    For your CFAPPLICATION tag as it relates and as documentation shows:

    <cfapplication name="myappname" sessionmanagement="Yes" setclientcookies="yes" setdomaincookies="no" sessiontimeout="#CreateTimeSpan(0,0,30,0)#">

    Is the typical code if you want your session timeouts to be higher than what the coldfusion administrator has it set for, which default install is 20 minutes for session timeout. In this example, I have it set to 30 minutes...and yes that is correct.

    This is for an admin application, which includes an article manager app I built. So since I do not want it timing out if I take 25 minutes to create an article...which it was before :)...I added the sessiontimeout to my CFAPP tag. And actually for admin applications I should really up it to 1-2 hours :).

    Anyways I digress: still trying to figure out how to format the 0.0208333333333 out as "30 minutes" to display on a page.

    Maybe a better way to summarize all of this is if you ignore all other code above, and wanted to:

    1. Take a value of 0.0208333333333 days (1440 minutes in a day / 30 minutes).
    2. display it to a page automatically formatted out to show :

    W Days X hours Y minutes Z seconds (seconds I dont really care about)

    But have it ignore any of these that are not > 1.

    Any clearer, or still totally confusing everyone? :)

    Thanks.
    Inspiring
    July 28, 2007
    Since you are referring to a timeout, which is normally expressed in seconds, as opposed to a query cache time which uses the time span, life would be a lot simpler if you asked the user how many seconds he wanted for his default.

    And 30 minutes is pretty long for for a default. You sure you don't mean 30 seconds?
    Inspiring
    July 28, 2007
    > 2. I want the SESSIONTIMEOUT and CFLOCK TIMEOUT to obviously be consistant.

    Ah no. No you do not. At all.

    The two concepts are really not related.

    You want your <cflock> timeout to be slightly more than a reasonable "worst
    case scenario" for the execution time of the code within the lock.

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    July 28, 2007
    The issue why I think this is not working properly, is when I do the code above for #sessionTimeout" onto a page, it displays as
    0.0208333333333
    For the timeout value.

    That is not necessarily the reason. At least, not in the session case. I expect the code

    <cfparam name="sessionTimeout" default="#CreateTimeSpan(0,0,30,0)#" />
    <cfapplication name="myappname" sessionmanagement="Yes" setclientcookies="yes" setdomaincookies="no" sessiontimeout="#sessionTimeout#">

    to be good. The function createTimeSpan() returns the number of days. That is precisely what the sessiontimeOut attribute gets. Realize that 30 minutes is the same as 0.0208333333333 days.

    Where the code makes a mistake is to assign the same value, 0.02083..., to the lock timeout. The two timeouts are different. Sessiontimeout is a number of days, whereas lock timeout is a number of seconds. The value 0.02 is just too small for lock timeout. Developers typically use values between 1 and 20 seconds.

    bhakalaAuthor
    Participating Frequently
    July 28, 2007
    I appreciate the critic and info on differences in the CFAPP timeout vs. the CFLOCK timeout. I have looked more into it and intend to use a set value for the CFLOCK timeout versus using the same variable.

    However the issue I am still having is trying to figure out how to display the sessionTimeout to the page formatted automatically. So instead of this 0.0208333333333 it would display '30 minutes'.

    CF has so many time / date format functions that I find it difficult to believe it doesn't have one for this.

    Thanks.
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    July 28, 2007
    However the issue I am still having is trying to figure out how to display the sessionTimeout to the page formatted automatically. So instead of this 0.0208333333333 it would display '30 minutes'.
    ...
    ...
    Anyways I digress: still trying to figure out how to format the 0.0208333333333 out as "30 minutes" to display on a page.


    <cfset sessiontimeout = createtimespan(0,0,30,0)>
    timeout in days: <cfoutput>#sessiontimeout #</cfoutput><br>
    timeout in minutes: <cfoutput>#sessiontimeout *24*60#</cfoutput>