Copy link to clipboard
Copied
Hello, all,
I'm trying to learn how to use CFTHREAD - just playing around with it, a bit - and I'm clearly missing something in the documentation.
As a "for example", I'm trying to use CFTHREAD to get the content of different web sites and output them from within a loop. Obviously this should be done asynchronously, as each page will have a different load time. But the output (even when using view source) remains blank. Timing, maybe?
<cfsilent>
<cfset urlList = ListToArray("http://www.ustranscom.mil/,https://news.google.com/,http://www.sddc.mil/,https://news.yahoo.com/,htt...") />
<cfset steList = ListToArray("USTRANSCOM,Google,SDDC,Yahoo!,AMC,Adobe") />
</cfsilent>
I've tried:
<cfloop from="1" to="#ArrayLen(urlList)#" index="idx"><cfset steList[idx] = lcase(REreplace(steList[idx],"[^\w]","","all")) />
<cfthread name="output#idx#" action="run" aURL="#urlList[idx]#">
<cfhttp url="#arguments.aURL#"></cfhttp>
</cfthread>Output: <cfdump var="output#idx#" />
</cfloop>
.. and I've tried:
<cfloop from="1" to="#ArrayLen(urlList)#" index="idx"><cfset steList[idx] = lcase(REreplace(steList[idx],"[^\w]","","all")) />
<cfthread name="output#idx#" action="run" aURL="#urlList[idx]#">
<cfhttp url="#arguments.aURL#"></cfhttp>Output: <cfdump var="#cfhttp#" />
</cfthread>
</cfloop>
Nothing. So, I'm assuming it's something totally simple and I'm just not seeing it. Can anyone help me to understand how CFTHREADS are used?
V/r,
^_^
Copy link to clipboard
Copied
Once the thread has been started it will run completely separately from the main current thread your page is running on. This means you wont be able to just dump it as its separate. You need to use the join action to bring it back to the main thread and allow you to dump the data.
When you join it back you have access to another cfthread variable with the data stored.
The example on the documentation is pretty similar to what you are trying but with feeds instead of urls - ColdFusion Help | cfthread
Copy link to clipboard
Copied
Hi, @haxtbh (Mentions are no longer working, for me.)
Thank you, for steering me in the right direction. I still had issues with the CF Help solution, but I did manage to find (based upon your recommendation) a SO thread that helped.
Much appreciated!
V/r,
^_^