Skip to main content
Known Participant
July 5, 2011
Question

One CFHTTP at a time

  • July 5, 2011
  • 2 replies
  • 696 views

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

    This topic has been closed for replies.

    2 replies

    Inspiring
    July 6, 2011

    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

    Inspiring
    July 5, 2011

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

    Owainnorth
    Inspiring
    July 6, 2011

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