Skip to main content
October 7, 2010
Question

What is a clever way

  • October 7, 2010
  • 3 replies
  • 1049 views

To avoid cfquery timeout errors?

Note: I can't do anything to make my db or server faster because its hosted

I am looking for a CF solution to avoid throwing the user a timeout error (which presents them with a custom error page).  What I'd like to do is have some logic try to reload the page x amount of times if it hasn't loaded in say... 20 seconds.

Any ideas?

    This topic has been closed for replies.

    3 replies

    dave_jf
    Participating Frequently
    October 7, 2010

    What version of CF are you using? You could use an asynchronous gateway to spawn the query and return to the user. This would prevent the user from getting a timeout.

    On the flip side... You should look at optimizing the code to prevent getting timeouts in the first place.

    --Dave

    October 7, 2010

    CF9 and like I said, the pages load exceptionally fast most of the time.  These aren't complex queries nor are my pages filled with too much code and data.

    Inspiring
    October 7, 2010

    this is on a shared host, right? If so... I'm afraid there probably

    isn't much you can do. Inconsistent behavior like this requires

    monitoring tools, and they aren't going to give them to you.

    I'd say you're now in the position where you have to push them to set

    up the tools necessary to monitor and diagnose these kinds of

    problems.

    Inspiring
    October 7, 2010

    I doubt you'll find a clever way, since this is a not-clever problem.

    You could try something like this:

    <cfset keepGoing = true>

    <cfset counter = 1>

    <cfloop condition="#keepGoing#">

    <cfset counter = counter +1>

    <cftry>

    <cfquery...>

    <cfset keepGoing = false>

    <cfcatch>

       ....

    <!--- so you don't keep trying forever -->

    <cfif counter eq 3>

      <cfset keepGoing = false>

    </cfif>

    </cfloop>

    <cfreturn queryVar>

    Definitely not pretty, but it would achieve part of what you want, which is to keep trying. IT does not achieve clever, because it's kind of a dumb problem to have ... sort of like the rats in "Bad Boys II" that keep eating the drug dealer's money: "It's a stupid problem to have, but it's  a problem nonetheless".

    Good luck!

    October 7, 2010

    How do I make the problem not so stupid?  I hate that it happens.  When the server is running the way it should the page load

    times are fractions of a second.  Then every once in awhile I run into these errors.  I don't understand.

    ilssac
    Inspiring
    October 7, 2010

    idesdema wrote:

    Any ideas?

    <cftry><cfcatch> blocks around the offending <cfquery...> block.

    Then you can have logic in the <cfcatch...> for database errors retry the code again if you like.