Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Not only is that not clever, it's ill advised.
If your query times out, immediately sending the same query to the db is asking for trouble. Without going into details, let's just say that my statement is not based on something I read on the internet somewhere.
Copy link to clipboard
Copied
I think I'll just live with the issue and just continue to scream and hollar at the hosting company.
Copy link to clipboard
Copied
I think that's your best approach, aside from seeking out a new host
should they refuse to be interested in helping you
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.