This content has been marked as final. Show 7 replies
> To ask a different way -- Is there a way to have CF "stand still" until the
> desired lines of code have finished executing?
Well there are ways to put a thread to sleep with ColdFusion. In CF8
there are tags|functions to control this, for previous versions you will
need to create and call a Java object. A quick Google would show you
But you do not need to do that in this case.
ColdFusion is NOT going to ever process the <img...> tag. That
is an HTML tag, not CFML tag and it is going to be processed by a
browser on the client. The client browser does not get the response
until ColdFusion is completely done building the entire response and
sends it to the client.
In fact, by the time the browser has got the request and is requesting
that <img...> file, ColdFusion has moved on and is working on a
completely new request.
I'm not explaining myself properly.
I'm in CF8.
I've done Google searches, but either I'm missing an answer that's in my face or I don't see how to do what I need.
To better explain my situation:
I have a CFM template.
It has an IMG tag. It refers to a JPG witha generiic name that does not yet exist.
In the CFM template, right before the IMG tag, is code to: Hit the database and retrieve a BLOB, then write that BLOB with the generic filename to the place the IMG tag refers to.
There *seems* to be some miscoordination going on. Maybe not, but it seems so. It seems the HTML is being served to the browser before the file is completely retrieved and written to disk.
So, I'm wondering if there's a way to keep CF from "moving on" and serving the HTML to the browser until it knows the file is retrieved and written to disk.
Or, does CF already do this? Meaning my problem lies elsewhere.
is there a reason why the JPG filename has to be generic?
if not, why not point the IMG tag at a CFM script that:
1. retrieves the JPG BLOB data from the DB
2. uses CFCONTENT to return the BLOB data as JPG mimetype?
> So, I'm wondering if there's a way to keep CF from "moving on" and serving the
> HTML to the browser until it knows the file is retrieved and written to disk.
As I mentioned there are ways to put the current thread to sleep in
ColdFusion. IIRC, CF8 has tags or functions to do this now. If not, or
for earlier versions of CFMX, you can use a Java thread object to sleep
Also you could create a file watcher that confirms that the file is
completely written before moving on. Search for an article titled
"Directory Watcher Dangers - A Follow-Up." It spells out how to create
a while loop that will wait until I file is completely written before
moving on with processing.
> Or, does CF already do this? Meaning my problem lies elsewhere.
That would be my first thought. I would think that since ColdFusion is
going to completely process the entire response before sending anything
to the browser. Then the browser is going to have to render the
received response to find the <img...> tag. Then it makes a new request
to get the <img...> file. I would think that this file would long be
written and ready and waiting.
You say you are using a generic name? Is this name getting reused
and|or replaced from request to request? If you follow the implications
of the above data flow, you can't easily reuse a 'generic' file name
that is shared between many requests without a strong possibility for
data sharing and|or race conditions. Could this be part of the problem?
Yes, the name needs to be generic. The filepath is not (it changes).
Intersting idea in using the template as the IMG tag source. Will try that.
Thanks, everyone, for the suggestions and help. Turns out it was a series of small errors, not the problem I thought it was. I appreciate the information, I'm sure it'll help in the future.
Long story about not using CFIMAGE/WriteToBrowser, I had to use the IMG tag in this situation due to a client requirement.