<HTML ><HEAD ><TITLE >Output Control Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="ovrimos_rollback" HREF="function.ovrimos-rollback.html"><LINK REL="NEXT" TITLE="flush" HREF="function.flush.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ovrimos-rollback.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.flush.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.outcontrol" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXV. Output Control Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN69952" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.intro" ></A >Introduction</H1 ><P > The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > or <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A >, only functions such as <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > and data between blocks of PHP code. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.requirements" ></A >Requirements</H1 ><P >No external libraries are needed to build this extension.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.installation" ></A >Installation</H1 ><P >There is no installation needed to use these functions; they are part of the PHP core.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.configuration" ></A >Runtime Configuration</H1 ><P > The behaviour of these functions is affected by settings in <TT CLASS="filename" >php.ini</TT >. </P ><P > <DIV CLASS="table" ><A NAME="AEN69970" ></A ><P ><B >Table 1. Output Control configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >output_buffering</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >output_handler</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >implicit_flush</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ></TBODY ></TABLE ></DIV > For further details and definition of the PHP_INI_* constants see <A HREF="function.ini-set.html" ><B CLASS="function" >ini_set()</B ></A >. </P ><P > Here is a short explanation of the configuration directives. <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.output-buffering" ></A ><TT CLASS="parameter" ><I >output_buffering</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A >/<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > You can enable output buffering for all files by setting this directive to 'On'. If you wish to limit the size of the buffer to a certain size - you can use a maximum number of bytes instead of 'On', as a value for this directive (e.g., output_buffering=4096). </P ></DD ><DT ><A NAME="ini.output-handler" ></A ><TT CLASS="parameter" ><I >output_handler</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > You can redirect all of the output of your scripts to a function. For example, if you set output_handler to <A HREF="function.mb-output-handler.html" ><B CLASS="function" >mb_output_handler()</B ></A >, character encoding will be transparently converted to the specified encoding. Setting any output handler automatically turns on output buffering. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > You cannot use both <A HREF="function.mb-output-handler.html" ><B CLASS="function" >mb_output_handler()</B ></A > with <B CLASS="function" >ob_inconv_handler()</B > and you cannot use both <A HREF="function.ob-gzhandler.html" ><B CLASS="function" >ob_gzhandler()</B ></A > and <A HREF="ref.zlib.html#ini.zlib.output-compression" >zlib.output_compression</A >. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.implicit-flush" ></A ><TT CLASS="parameter" ><I >implicit_flush</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > <TT CLASS="constant" ><B >FALSE</B ></TT > by default. Changing this to <TT CLASS="constant" ><B >TRUE</B ></TT > tells PHP to tell the output layer to flush itself automatically after every output block. This is equivalent to calling the <TT CLASS="literal" >PHP</TT > function <A HREF="function.flush.html" ><B CLASS="function" >flush()</B ></A > after each and every call to <A HREF="function.print.html" ><B CLASS="function" >print()</B ></A > or <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > and each and every <TT CLASS="literal" >HTML</TT > block. </P ><P > When using <TT CLASS="literal" >PHP</TT > within an web environment, turning this option on has serious performance implications and is generally recommended for debugging purposes only. This value defaults to <TT CLASS="constant" ><B >TRUE</B ></TT > when operating under the <TT CLASS="literal" >CLI SAPI</TT >. </P ><P > See also <A HREF="function.ob-implicit-flush.html" ><B CLASS="function" >ob_implicit_flush()</B ></A >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.resources" ></A >Resource Types</H1 ><P >This extension has no resource types defined.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.constants" ></A >Predefined Constants</H1 ><P >This extension has no constants defined.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.examples" ></A >Examples</H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN70042" ></A ><P ><B >Example 1. Output Control example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php ob_start(); echo "Hello\n"; setcookie ("cookiename", "cookiedata"); ob_end_flush(); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > In the above example, the output from <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > would be stored in the output buffer until <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A > was called. In the mean time, the call to <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > successfully stored a cookie without causing an error. (You can not normally send headers to the browser after data has already been sent.) </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > When upgrading from PHP 4.1 (and 4.2) to 4.3 that due to a bug in earlier versions you must ensure that <TT CLASS="literal" >implict_flush</TT > is <TT CLASS="literal" >OFF</TT > in your <TT CLASS="literal" >php.ini</TT >, otherwise any output with <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A > will be not be hidden from output. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.seealso" ></A >See Also</H1 ><P > See also <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > and <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.flush.html" >flush</A > -- Flush the output buffer</DT ><DT ><A HREF="function.ob-clean.html" >ob_clean</A > -- Clean (erase) the output buffer </DT ><DT ><A HREF="function.ob-end-clean.html" >ob_end_clean</A > -- Clean (erase) the output buffer and turn off output buffering </DT ><DT ><A HREF="function.ob-end-flush.html" >ob_end_flush</A > -- Flush (send) the output buffer and turn off output buffering </DT ><DT ><A HREF="function.ob-flush.html" >ob_flush</A > -- Flush (send) the output buffer </DT ><DT ><A HREF="function.ob-get-contents.html" >ob_get_contents</A > -- Return the contents of the output buffer </DT ><DT ><A HREF="function.ob-get-length.html" >ob_get_length</A > -- Return the length of the output buffer </DT ><DT ><A HREF="function.ob-get-level.html" >ob_get_level</A > -- Return the nesting level of the output buffering mechanism </DT ><DT ><A HREF="function.ob-get-status.html" >ob_get_status</A > -- Get status of output buffers </DT ><DT ><A HREF="function.ob-gzhandler.html" >ob_gzhandler</A > -- ob_start callback function to gzip output buffer </DT ><DT ><A HREF="function.ob-implicit-flush.html" >ob_implicit_flush</A > -- Turn implicit flush on/off </DT ><DT ><A HREF="function.ob-start.html" >ob_start</A > -- Turn on output buffering</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ovrimos-rollback.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.flush.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ovrimos_rollback</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >flush</TD ></TR ></TABLE ></DIV ></BODY ></HTML >