cfflush

Description

Flushes currently available data to the client.

Category

Page processing tags

Syntax


<cfflush

  interval = integer number of bytes> 

See also

cfcache, cfheader, cfinclude, cfsetting, cfsilent

Attributes

Attribute
Description
interval
Optional. Flush the output each time at least the specified number of bytes become available. HTML headers, and any data that is already available when you make this call, are not included in the count.

Usage

The first time you use the cfflush tag on a page, it sends back the HTML headers and any other available HTML. Subsequent cfflush tags on the page send only the output that was generated since the previous flush.

When you flush data, ensure that enough information is available, as some browsers may not respond if you flush only a very small amount. Similarly, set the interval attribute for a reasonable size, such as a few hundred bytes or more, but not many thousands of bytes.

Use cfflush with the interval attribute only when a large amount of output will be 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) may cause unexpected errors when CFML tags that modify HTML headers are executed.


Caution

Once you have used the cfflush tag on a page, any CFML function or tag on the page that modifies the HTML header causes an error. These include the cfcontent, cfcookie, cfform, cfheader, cfhtmlhead, and cflocation tags. You also get an error if you use the cfset tag to set a cookie scope variable. All errors except cookie errors can be caught with a cfcatch type = "template" tag. Cookie errors can be caught with cfcatch type = "Any".



Note

Normally, cferror discards the current output buffer and replaces it with the contents of the error template. cfflush 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, and this content is not sent to the client. The content of the error template appears to the client after the bytes that have already been sent.


Example

The following example uses cfloop tags and the rand random number generating function to delay the generation of data for display. It simulates a situation in which a page is slow to retrieve its first data, and in which additional information is generated slowly, and can be displayed incrementally.

<html>

<head>

  <title>Your Magic numbers</title>

</head>



<body>

<H1>Your Magic numbers</H1>

<P>It will take us a little while to calculate your ten 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>

<H2>We are sure you will agree it was worth the short wait!</H2>

<cfflush>



<cfflush interval=10>

<!--- Delay Loop to make is seem harder --->

<cfloop index="randomindex" from="1" to="200000" step="1">

  <cfset random=rand()>

</cfloop>



<!--- Now slowly output 10 random numbers --->

<cfloop index="Myindex" from="1" to="10" step="1">

  <cfloop index="randomindex" from="1" to="100000" step="1">

    <cfset random=rand()>

  </cfloop>

  <cfoutput>

    Magic number number #Myindex# is:&nbsp;&nbsp;#RandRange( 

100000, 999999)#<br><br>

  </cfoutput>

</cfloop>

</body>

</html>





Banner.Novgorod.Ru