PHP Output Control Functions

Beginner
5 min read
Updated: Nov 2026
17 function guides
Function index

About This Index

This page is the PHP Output Control Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn why buffering exists, how to capture with ob_get_clean(), flush() versus ob_flush(), and nested levels on /php/output-control. Use this page when you need a specific function such as ob_start(), ob_get_clean(), or flush().

Beginner path.

Start with ob_start() and ob_get_clean()—then learn ob_flush() versus flush(), and finish with ob_get_level() for nested buffers.

Seventeen guides.

Every Output Control function in this series appears below in four categories: start & inspect, send & clear, handlers & flush helpers, and URL rewrite vars.

How to Call a PHP Output Control Function

Output Control helpers are global functions—call them directly. Start a buffer, write output, then capture, send, or discard:

PHP
ob_start();
echo 'buffered text';
$copy = ob_get_contents();              // string|false
$len  = ob_get_length();                // int|false
$lvl  = ob_get_level();                 // int
$text = ob_get_clean();                 // capture + end

ob_start();
echo 'chunk';
ob_flush();                             // send, keep buffering
flush();                                // system write buffers
ob_end_clean();                         // discard + end

$handlers = ob_list_handlers();         // array of names

PHP Output Control Functions Table

All function guides in this PHP tutorial series (17 tutorials in 4 categories).

Start & inspect

6 functions

Turn buffering on, copy buffer contents, and inspect length, nesting level, status, and active handlers.

FunctionDescriptionTutorial
ob_start()Turn on output buffering; optional callback filters each flush.Try it
ob_get_contents()Return the contents of the active buffer without ending it.Try it
ob_get_length()Return the length of the active output buffer.Try it
ob_get_level()Return how many nested output buffers are active.Try it
ob_get_status()Return status information about the active buffer (or all levels).Try it
ob_list_handlers()List the names of the active output handlers.Try it

Send & clear

6 functions

Send buffer contents to the next layer, erase draft output, or capture text and end the buffer in one step.

FunctionDescriptionTutorial
ob_clean()Erase the active buffer contents and keep buffering on.Try it
ob_end_clean()Erase the active buffer and turn that level off.Try it
ob_flush()Send (flush) the active buffer and keep buffering on.Try it
ob_end_flush()Send the active buffer and turn that level off.Try it
ob_get_clean()Get the buffer contents and turn that level off.Try it
ob_get_flush()Get the buffer contents, flush them, and turn that level off.Try it

Handlers & flush helpers

3 functions

Push system write buffers, use the gzip output callback, or enable implicit flush after output.

FunctionDescriptionTutorial
flush()Flush system write buffers (does not empty an ob_start buffer).Try it
ob_gzhandler()Gzip callback used with ob_start() to compress buffered output.Try it
ob_implicit_flush()Turn implicit flushing on or off so output may flush automatically.Try it

URL rewrite vars

2 functions

Register or clear name/value pairs used when PHP rewrites URLs and forms in buffered output.

FunctionDescriptionTutorial
output_add_rewrite_var()Add a name/value pair for URL and form rewriting.Try it
output_reset_rewrite_vars()Reset all rewrite variables previously added.Try it

Frequently Asked Questions

They are the built-in PHP functions for output buffering: start a buffer with ob_start(), inspect it with ob_get_contents(), ob_get_length(), and ob_get_level(), send or clear it with ob_flush() and ob_end_clean(), and helpers such as flush(), ob_gzhandler(), and output_add_rewrite_var(). This index links to a full tutorial for each one.
The Output Control page teaches the ideas: why buffering exists, capturing with ob_get_clean(), flush() versus ob_flush(), and nested levels, with three fixed examples. This index lists every function tutorial so you can open flush(), ob_start(), ob_get_clean(), and the rest.
Start with ob_start() and ob_get_clean() so you can capture echo into a string. Then learn ob_flush() versus flush(), and inspect helpers such as ob_get_length() and ob_get_level(). The sidebar begins with flush() because of alphabetical order.
flush() pushes system write buffers toward the OS or SAPI. ob_flush() sends the active output buffer started with ob_start() and keeps that buffer open. If echo is still held by Output Control, flush() alone will not deliver it.
Each successful ob_start() adds one level. ob_get_level() reports how many are active. Ending the top buffer with ob_end_clean() or ob_end_flush() drops the level by one. Inner buffers must end before outer buffers see that text.
Open flush() next (it is the first guide in sidebar order), or jump to ob_start() and ob_get_clean() if you want the capture pattern first. Read PHP Output Control if the groups below still feel unfamiliar.

Start with flush()

Open the next guide—syntax, examples, and FAQs.

flush() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful