Created
February 26, 2014 12:54
-
-
Save bennadel/9229005 to your computer and use it in GitHub Desktop.
Using The Timeout Attribute With CFHttp In ColdFusion To Limit Blocking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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