Handling Timeout Requests

As explained in the ColdFusion Administrator the Request Timeout property allows us to terminate requests that take longer than the specified time. This prevents unusually long requests from occupying server resources and impairing the performance of other requests. There are two ways to control this time. The first and easiest is to set a global time for your server in the administrator. When logged in click on the settings button under Server Settings. From there locate the timeout request and change it to a value of your choice. The attribute is a number and represents seconds. If you are on shared host that this is not an option for you. Lucky for you there is a way to change this programatically. You can use the cfsetting tag and use the requestTimeout attribute. From the livedocs we can see this takes precedence over the the administrator timeout. You could set this in your application component for your entire system or you can use on a per template basis.



Categories: ColdFusion

About The Author

My name is Dan Vega and I am a Software Developer based out of Cleveland OH. I love to play with new technologies and write about my experiences here. When I am not busy being a full time geek I love to lift heavy weights and hang out with friends and family. If you have any questions please don't hesitate to contact me.

Follow me on:
  • http://www.bennadel.com Ben Nadel

    Dan, I have a question about handling time out errors that maybe you can help me with. Apparently, there are two different time outs: page time outs and query time outs ; these operate under different settings (as far as I know). The problem I run into occasionally is that a query will execute for longer than the page timeout (as a page will not time out while a query is still running… I THINK) but then, once the query stops running, the page times out immediately aftewards and this timeout seems to stop even the onError event method from being fired.

    I am not sure if I am explaining that well, but essentially what seems to be happening is that the page times out in a such a way that not even the error handler (onError application even method) has time to be run. Does this sound crazy? How can I handle this? Does the execution time of the page carry over to the onError event method?

  • http://therealdanvega.com Dan

    Ben,
    I am not sure that there are two different timeout settings. Have you tried bumping out the requestTimeout for that specfic template to something just to see if the template executes?

  • http://www.bennadel.com Ben Nadel

    Hey Dan,

    Can you take a look at this, I would love some feedback:

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

    While this does not involve a CFQuery tag, this partially demonstrates what I was talking about. The OnError() event simply cannot handle the request time out error. Other than pumping up the request time out, I cannot think of a better way to handle this. And, upping the time out is not always the solution I can have – think about a page where I want to enforce the time out AND do some logging. I cannot figure this one out :(

  • Dan

    Ben,
    Why not wrap the cfquery code in a try / catch block. You can then look for that specific error or any for that matter and handle it accordingly. Just a thought!