Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

One CFHTTP at a time

Community Beginner ,
Jul 05, 2011 Jul 05, 2011

Hello,

I'm trying to run a process with CFHTTP, and waiting until it's finished, then run another CFHTTP page. Will the second request wait for the first request to complete before running?

If not, how can I do this?

Thanks,

Peter

607
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2011 Jul 05, 2011

Stick a command in between that refers to something from the first cfhttp.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 05, 2011 Jul 05, 2011

The vast majority of CF is single-threaded anyway, I would've thought this is the default bahaviour?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2011 Jul 06, 2011
LATEST

OK, faced with your dilemma, this is what I would do:

* start from a position that as a general rule, CF code runs sequentially, completing each instruction in series, one at a time: the previous instruction completing before the next starts.  There's no reason to think CFHTTP is any different to any other CF instruction.

* RTFM, to see what that has to say.  The docs for CFHTTP are here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ffc.html.  In reading that lot, it strongly hints at what the answer is.

* not being one to trust the CF docs, I would spend 5min knocking some code together to test this.

Indeed those three steps are exactly what I did when prepping for my response to you.

I think you should try to work this out for yourself, rather than asking someone else, but here's the code I used to test:

<!--- test.cfm --->

<cflog file="cfhttpSerialisation" text="Before first call">
<cfhttp method="get" url="http://#CGI.http_host#/path/to/target.cfm">
<cflog file="cfhttpSerialisation" text="After first call">
<cfset sleep(5000)>
<cflog file="cfhttpSerialisation" text="Before second call">
<cfhttp method="get" url="http://#CGI.http_host#/path/to/target.cfm">
<cflog file="cfhttpSerialisation" text="After second call">

<!--- target.cfm --->

<cflog file="cfhttpSerialisation" text="Top of target.cfm">
<cfset sleep(5000)>
<cflog file="cfhttpSerialisation" text="Bottom of target.cfm">

Obviously change /path/to/target.cfm to be correct.

What does running that tell you?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources