User Guide Cancel

cfflush

 

Description

Flushes currently available data to the client.

Category

Data output tagsPage processing tags

Syntax

<cfflush
interval = "integer number of bytes">

 

Note: You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.

See also

cfcachecfheadercfincludecfsettingcfsilent

Attributes

Attribute

Req/Opt

Default

Description

interval

Optional

 

Integer. Flushes output each time this number of bytes becomes available. HTML headers, and data that is already available when the tag is executed, are omitted from the count.

Usage

The first occurrence of this tag on a page sends back the HTML headers and any other available HTML. Subsequent cfflush tags on the page send only the output that was generated after the previous flush.
When you flush data, ensure that enough information is available, as some browsers might not respond if you flush only a small amount. Similarly, set the interval attribute for a few hundred bytes or more, but not thousands of bytes.Use the interval attribute only when a large amount of output is sent to the client, such as in a cfloop or a cfoutput of a large query. Using this form globally (such as in the Application.cfm file) might cause unexpected errors when CFML tags that modify HTML headers are executed. Because the cfflush tag sends data to the browser when it executes, it has several limitations, including the following:

  • Using any of the following tags or functions on a page anywhere after the cfflush tag can cause errors or unexpected results: cfcontent, cfcookie, cfform, cfheader, cfhtmlhead, cflocation, and SetLocale. Similarly, do not use any tags that use AJAX features, including cfdiv, cflayout, cflayoutarea, cfpod, cfsprydataset, cftooltip, cfwindow, or HTML format cfgrid, cftree, cftextarea, or cfinput (using autosuggest or datefield attributes) tags. All of the preceding tags and functions normally modify the HTML header, but cannot do so after a cfflush tag, because the cfflush sends the header.
  • Using the cfset tag to set a cookie anywhere on a page that has a cfflush tag does not set the cookie in the browser.
  • Using the cfflush tag in the body of several tags, including cfsavecontent, cfquery, and custom tags, causes errors.
  • If you save Client variables as cookies, any client variables that you set after a cfflushtag are not saved in the browser.

    Note: Normally, the cferror tag discards the current output buffer and replaces it with the contents of the error page. The cfflush tag discards the current buffer. As a result, the Error.GeneratedContent variable resulting from a cferror tag after a cfflush contains any contents of the output buffer that has not been flushed. This content is not sent to the client. The content of the error page displays to the client after the bytes that have been sent.

    To disable webserver buffer, change the iis_buffer_enable to false in the cfroot\config\wsconfig\1\isapi_redirect.properties file. Disable webserver buffer if you want cfflush to work over an IIS connector. If your application does not use cfflush , set it to true for increase in the performance.

Example

The following example uses cfloop tags and the rand random number generating function to delay data display. It simulates a page that is slow to generate data.

<h1>Your Magic numbers</h1>
<p>It will take us a little while to calculate your five magic numbers. It takes a lot of work to find numbers that truly fit your personality. So relax for a minute or so while we do the hard work for you.</p>
<cfflush>
<cfset sleep(1000)>
<cfflush interval=10>
<!--- Now slowly output 5 random numbers, flushing the buffer for every 300 bytes accumulated. --->
<cfloop index="Myindex" from="1" to="5" step="1">
<cfset sleep(1000)>
<cfoutput>
Magic number #Myindex# is:&nbsp;&nbsp;#RandRange(100000, 999999)#<br><br>
</cfoutput>
</cfloop>
<p>If you saw no delay between lines being written (and instead they were written all at once after a few seconds delay), and you're making this request via IIS,
note that you need to set iis_buffer_enable=false in the isapi_redirect.properties file, as discussed in the docs here, and then restart your IIS site to pick up the change to that file.</p>
<h1>Your Magic numbers</h1> <p>It will take us a little while to calculate your five magic numbers. It takes a lot of work to find numbers that truly fit your personality. So relax for a minute or so while we do the hard work for you.</p> <cfflush> <cfset sleep(1000)> <cfflush interval=10> <!--- Now slowly output 5 random numbers, flushing the buffer for every 300 bytes accumulated. ---> <cfloop index="Myindex" from="1" to="5" step="1"> <cfset sleep(1000)> <cfoutput> Magic number #Myindex# is:&nbsp;&nbsp;#RandRange(100000, 999999)#<br><br> </cfoutput> </cfloop> <p>If you saw no delay between lines being written (and instead they were written all at once after a few seconds delay), and you're making this request via IIS, note that you need to set iis_buffer_enable=false in the isapi_redirect.properties file, as discussed in the docs here, and then restart your IIS site to pick up the change to that file.</p>
<h1>Your Magic numbers</h1>
<p>It will take us a little while to calculate your five magic numbers. It takes a lot of work to find numbers that truly fit your personality. So relax for a minute or so while we do the hard work for you.</p>
<cfflush>
<cfset sleep(1000)>
 
<cfflush interval=10>
<!--- Now slowly output 5 random numbers, flushing the buffer for every 300 bytes accumulated. --->
<cfloop index="Myindex" from="1" to="5" step="1">
  <cfset sleep(1000)>
  <cfoutput>
  Magic number #Myindex# is:&nbsp;&nbsp;#RandRange(100000, 999999)#<br><br>
  </cfoutput>
</cfloop>
 
<p>If you saw no delay between lines being written (and instead they were written all at once after a few seconds delay), and you're making this request via IIS,
note that you need to set iis_buffer_enable=false in the isapi_redirect.properties file, as discussed in the docs here, and then restart your IIS site to pick up the change to that file.</p>

Get help faster and easier

New user?