RequestMonitor.getRequestTimeout()

Ever wanted to know what the request timeout is for the currently-running ColdFusion request? The static 'getRequestTimeout()' method on the 'coldfusion.runtime.RequestMonitor' class knows. Tested to work on both CF7 and CF8.

Why might you want to know? So you can set a request timeout, but only if it's not lower than what is already set. Specific use case: I have a method that imports a data file and it takes a while, so I set a 120 second timeout. But I also have a method that imports a directory of data files, and want to set the timeout to quite a bit longer. Of course, the later method calls the former, and I don't want the former to be lowering the timeout I just set to allow for multiple files. So instead of this:

<cfsetting requesttimeout="120" />

I can do this instead:

<cfset monitor = createObject("java", "coldfusion.runtime.RequestMonitor") />
<cfsetting requesttimeout="#max(monitor.getRequestTimeout(), 120)#" />

and ensure that the timeout is a least 120 seconds, but let it stay higher if it already is.  Or, in handy UDF form:

<cfset requestMonitor = createObject("java", "coldfusion.runtime.RequestMonitor") />
<cffunction name="requireRequestTimeout" access="private" output="false" return="boolean"
  hint="I ensure the request timeout is at least what is specified, and return
    whether or not the timeout was increased by this call.">
  <cfargument name="timeout" type="numeric" required="true" />
  <cfif timeout GT requestMonitor.getRequestTimeout()>
    <cfsetting requesttimeout="#timeout#" />
    <cfreturn true />
  </cfif>
  <cfreturn false />
</cffunction>

4 responses to “RequestMonitor.getRequestTimeout()”

  1. Ben Nadel

    Barney, this is wicked cool! This would totally jive well with my ideas on disaster recovery:

    http://www.bennadel.com/index.cfm?dax=blog:660.view

    There, I am randomly picking a new requesttimeout, but it would be so much better to actually have an existing time to work from. Thanks!

  2. Ben Nadel

    I am gonna include this in a post on monday. Thanks!

  3. Getting the current RequestTimeout » ghidinelli.com

    [...] card, it was reset down to just 300 seconds and so my batch processing would time out. Thanks to a clever but woefully named post by Barney Boisvert, getting the request timeout of the current context is super [...]