6 Replies Latest reply on Apr 18, 2013 1:32 AM by meensi

    Call a function at specific intervals

    meensi Level 2


      I need to call a function or page at specific intervals. Or I need a ping a page at specific intervals, to keep the session alive.


      I found window.setInterval() works fine. Is there any such function in coldfusion?

        • 1. Re: Call a function at specific intervals

          put your function in a cfc and use cfschedule to call to that method.  Example :




            <cffunction name="callMe" access="remote">

               .. do stuff here ..



          Setup a scheduled task in coldfusion to call your url every X minutes :




          If you have arguments, pass them in as url variables.

          • 2. Re: Call a function at specific intervals
            Dan Bracuk Level 5

            Write a page that does a meta-refresh to itself and stick it into an iframe of the page that needs it.

            • 3. Re: Call a function at specific intervals
              pete_freitag Adobe Community Professional

              IF you are doing the refresh to keep the session alive, then you probably want to do this client side using Javascript window.setInterval as you suggested or with the iframe meta-refresh as Dan suggested. Doing it with CF via a scheduled task will not preserve the session, unless you pass the session id's so you would need to create a lot of scheduled tasks, or use threads, either way it sounds like something you want to do client side.

              1 person found this helpful
              • 4. Re: Call a function at specific intervals
                Aegis Kleais Level 3

                Is there a reason why you want to keep the sessions alive indefinitely?  Are you prohibited from changing the session timeouts on your hosting environment?


                If so, a JS-enabled solution would be to call a remote CFC (as suggested) so that it sees activity on the current session.  However, if the user does not have JS enabled on the browser and you cannot setup an AJAX call to a remote CFC, then a meta-refresh would keep the session alive, however they perform an HTTP GET which would be the same as refreshing the page (resetting/losing form values and/or interrupting user activity and position)

                • 5. Re: Call a function at specific intervals
                  Dan Bracuk Level 5

                  It's a rare requirement, but it's still a requirement. 


                  The last time I wrote something like that is a situation where the user has to edit a some data before forwarding it on.  It was a time consuming process because she has to look up the correct answer from other applications as she goes.  This particular page is part of an application that has a 20 minute timeout.

                  • 6. Re: Call a function at specific intervals
                    meensi Level 2

                    Yes, As Dan suggested I wanted to keep the session alive only for one page in my application, where the user will take longer time to fill out the forms.:)


                    Presently i m using window.setInterval and calling a function which in turns calls .cfm page and it works fine.

                    Just wanted to know whether we can same kind of function in coldfusion.


                    CFSCHEDULE- good idea, but my customer is not preferring this one.


                    Thanks all for your replies.