Skip to main content
April 9, 2010
Question

cfthread and cfhttp

  • April 9, 2010
  • 1 reply
  • 2033 views

Whats the default timeout period for a fire and forget cfthread in cf9? from my tests and monitoring the server, the threads gets killed after it hits the request timeout period mentioned in the admin.

Is this the expected behaviour?

I need to know this since I have this project where I need to post easily more than 1gb file over cfhttp, Whenever I use the cfhttp inside a thread, the cfhttp timeouts aren't respected any more but only the threads timeout period from admin.

thank u for ur help

Here are the codes

timer.cfm

<cfsetting requesttimeout="10000000000000">
<cfthread action="sleep" duration="600000">
</cfthread>

index.cfm


<html>
<body>

     <p>threadcfbookclub</p>
     <cfthread action="run" name="testhread_#now()#">
          
          <cftry>
               <cfhttp timeout="60" throwonerror="true"   url="http://localhost/thread/timer.cfm"
           />          
          <cfcatch type="any">
               <cfrethrow>
          </cfcatch>
          </cftry>

          <!---<cfthrow type='test' message="test">--->
     </cfthread>
</body>
</html>

app.cfc

component  output="false"
{
     this.name = "thread";
}

Thx

Al

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    April 9, 2010
    timer.cfm
    <cfsetting requesttimeout="10000000000000">
    <cfthread action="sleep" duration="600000">
    </cfthread>
    app.cfc
    component  output="false"
    {
         this.name = "thread";
    }

    I don't see the point of all that. They play no part in the story you've told.

    Whats the default timeout period for a fire and forget cfthread in
    cf9? from my tests and monitoring the server, the threads gets killed
    after it hits the request timeout period mentioned in the admin.

    Is this the
    expected behaviour?

    Yes, that's the expected behaviour. The timeout attribute only applies to the join action of threads. In your case, the page thread is the main thread, but you haven't joined it to the cfhttp thread. So the timeout settings will be those of main page alone.

    The cfhttp thread will indeed be fired and forgotten.  In case of problems, you should be looking at the spawned thread for clues. To start with, though it may not be the cause, the value now() has spaces and so is a poor thread name.

    Secondly, the cfhttp timeout value of 60 seconds is too small for your requirements. Leave out the timeout attribute altogether. The thread would then wait till the cfhttp tag finishes.

    Thirdly, the spawned thread has no page context, so what's with all the try-catch and stuff? Leave it out.

    Your code could be as simple as:

    <cfset threadName = "testhread_" & dateformat(now(),"yyyy_mm_dd") & timeformat(now(),"_HH_MM_SS")>

    <cfthread action="run" name="#threadName#">        
           <cfhttp url="http://localhost/thread/timer.cfm"/>         
    </cfthread>