Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created February 26, 2014 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennadel/9229005 to your computer and use it in GitHub Desktop.
Save bennadel/9229005 to your computer and use it in GitHub Desktop.
Using The Timeout Attribute With CFHttp In ColdFusion To Limit Blocking
<cfscript>
// Build the common arguments to be used across both HTTP request.
// I'm doing this just to emphasize that the only thing changing
// in the second request is the timeout-related arguments.
httpArguments = {
method = "get",
url = "http://#cgi.server_name##getDirectoryFromPath( cgi.script_name )#long-task.cfm"
};
// ------------------------------------------------------ //
// ------------------------------------------------------ //
// Block the current page request until the HTTP request returns.
apiRequest = new Http( argumentCollection = httpArguments );
writeDump(
var = apiRequest.send().getPrefix(),
label = "No Timeout"
);
// ------------------------------------------------------ //
// ------------------------------------------------------ //
// Block the current page for a maximum of 1-second, even if the
// HTTP request has not returned.
apiRequest = new Http(
argumentCollection = httpArguments,
timeout = 1
);
writeDump(
var = apiRequest.send().getPrefix(),
label = "1-Second Timeout"
);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment