• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Call a function at specific intervals

Contributor ,
Apr 16, 2013 Apr 16, 2013

Copy link to clipboard

Copied

Hi,

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?

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

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

remoteCalls.cfc

<cfcomponent>

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

     .. do stuff here ..

  </cffunction>

</cfcomponent>

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

http://www.domain.com/remoteCalls.cfc?method=callMe

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 18, 2013 Apr 18, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation