Checking To See If CFFlush Has Already Been Executed Part II

Posted November 3, 2006 at 8:48 AM

Tags: ColdFusion

A while back, I posted that you could check to see if CFFlush had been executed earlier in the page processing by trying to set the header and catching any errors that were thrown. This morning, though, I was poking around in ColdFusion's page context (returned via GetPageContext()) and it turns out there is a much more simple way to do this; all you have to do is check to see if the response headers have been committed (written to the output stream):

 Launch code in new window » Download code as text file »

  • <!--- Check to see if a CFFlush tag has been executed. --->
  • CFFlush: #GetPageContext().GetResponse().IsCommitted()#
  •  
  • <!--- Flush the page. --->
  • <cfflush />
  •  
  • <!--- Check to see if a CFFlush tag has been executed. --->
  • CFFlush: #GetPageContext().GetResponse().IsCommitted()#

This gives us the output:

No
Yes

That's some easy stuff right there. No, keep in mind, this is not just for the CFFlush tag. This is a general way to see if content has already been sent to the browser.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page




Reader Comments

Nov 3, 2006 at 9:28 AM // reply »
111 Comments

Hey Ben,

Just general comment (not post specific). Lots of very cool posts - really enjoying all this. I notice Andy's linking to some of your posts too for the Scottish CFUG guys (and others) at http://www.creative-restraint.co.uk/blog/index.cfm/2006/11/3/Weekly-Blog-Round-Up.

One small thing - bennadel.com works, but www.bennadel.com doesn't. Any way you could fix the DNS and/or host headers so you allow both (or set up a redirect)?


Nov 3, 2006 at 11:31 AM // reply »
7,539 Comments

Pete,

Thanks for the heads up on the www issue. I have to say that both work for me. But, I talked to one of my more server-savvy co-workers and he says that while all the server stuff is set up to handle it, there is a chance IIS doesn't have it correct. We are waiting for our production box login (from my boss) and we will check the host headers.

I of course know nothing about all this jazz :)

Glad you are enjoying the posts. I am working my way through posts right now. I unfortuantely cannot contribute opinions regarding DAO vs. Gateways cause I don't know that stuff yet... but hopefully I will soon.


Nov 3, 2006 at 12:29 PM // reply »
7,539 Comments

Pete,

The server guys here tell me there is no reason that www.bennadel.com should not be working. Do you have any suggestions?


Nov 3, 2006 at 1:27 PM // reply »
92 Comments

No trouble here viewing your site with www. infront of the domain name. A great post. I've seen the same implemented in the index.cfm of cfwheels (but for a different purpose than cfflush but still deals with output to the browser) and currently use it myself for something new I built. Comes in handy.


Nov 3, 2006 at 1:51 PM // reply »
111 Comments

Ooops - sorry having u chase round Ben - my bad.

Did a link in a comment to your site and had a period in the URL so it was www.bennadel.com. that didn't work (trailing period). Sorry about that! I've just been caught out by the www thing back when I first started admin'ing my sites and I jumped to the (wrong) conclusion.

Say sorry to the server guy for me!


Nov 3, 2006 at 3:19 PM // reply »
7,539 Comments

No worries :) The server guy has to earn his keep ;)


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 18, 2010 at 1:18 PM
Finally Finished Ayn Rand's Atlas Shrugged Audio Book
@joaopft, Not disputing what you say - but... If I understand you correctly, you are saying that Positivism is based on sense experience (what I experience is what is), but Quantum theory states tha ... read »
Mar 18, 2010 at 11:48 AM
Duplicate() Much Faster Than ColdFusion Query-of-Queries
I am working on a massive xml parsing, qofq app to create 2 seperate xml files. I just don't understand the concept/purpose of duplicate function, are you duplicating the data or the row, into a new ... read »
Mar 18, 2010 at 11:22 AM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Zarko, Ha ha, you know ColdFusion is my first love ;) ... read »
Mar 18, 2010 at 11:15 AM
Exploring ColdFusion Component Runtime Class Properties And Serialization
Hi Ben, nice to have you back! I already gave up on you, thinking you'll write about jQuery and iPhone for the rest our our lives! :) ... read »
Mar 18, 2010 at 10:36 AM
Ask Ben: Javascript Replace And Multiple Lines / Line Breaks
@Ben Nadel, Hey Ben, thanks for you're response. It works!! However.. if you could please kindly look at http://edeals.zzl.org/divchange2.php where I am trying it out you will see that with the " ... read »
Mar 18, 2010 at 9:56 AM
SQL COUNT( NULLIF( .. ) ) Is Totally Awesome
This works too. I learned this trick a long time ago and it's really powerful for flags. SELECT g.hair , COUNT(*) AS girl_count , sum(did_date) AS did_date_count , sum(abs(did_date - 1)) AS did_ ... read »
Mar 18, 2010 at 9:16 AM
Using A SQL JOIN In A SQL DELETE Statement (Thanks Pinal Dave!)
Forget the last part of that. Wasn't thinking straight and hadn't done it exactly that way myself. It'll work if you're doing an 'In' but if you're doing a 'Not In' as above it'll do each check acr ... read »
Mar 18, 2010 at 9:16 AM
Ask Ben: Blocking WSDL Access In A ColdFusion Application
Ben, Robert great stuff that I can use. Thanks. ... read »