In PHP, ob_flush() sends the contents of the active output buffer and keeps that buffer turned on.
After a flush, the buffer is empty but still active, so new echo calls are captured again. This is different from flush(), which only pushes system write buffers and does not empty an ob_start() buffer.
Syntax
Call ob_flush() with the values you need. Start with this line.
PHP
$ok = ob_flush();
Call
What it does
ob_flush()
Sends the active buffer and keeps buffering; returns true on success.
ob_start(); echo "x"; ob_flush();
Sends "x"; the buffer stays active and empty.
ob_get_length()
Often 0 right after a successful ob_flush().
ob_flush() needs a flushable active buffer. With nested buffers, flushed data goes to the next outer buffer. Pair with flush() only when you also need system buffers pushed; they are separate steps.
Library declarations
PHP
ob_flush(): bool
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
bool
true on success, false on failure.
PHP Examples
Example 1 — Flush While Keeping the Buffer
Flush once, write more, then end-clean so only the second write remains to capture—and the first write was already sent.
after flush(): 'demo'
after ob_flush(): ''
outer received: 'demo'
How It Works
An outer buffer wraps an inner buffer that holds "demo".
flush() runs; the inner copy is still "demo" because flush() does not empty output buffers.
ob_flush() sends "demo" into the outer buffer and leaves the inner buffer empty.
We end both buffers and print the three snapshots.
Frequently Asked Questions
ob_flush() sends the active output buffer contents and keeps buffering on, so the buffer is empty but still active.
ob_flush() sends the ob_start() buffer. flush() only pushes system write buffers and does not empty the output buffer.
ob_flush() keeps the buffer active. ob_end_flush() sends and then turns the top buffer off.
No. It returns true or false. Use ob_get_contents() before flushing, or ob_get_flush() to get the string while flushing and ending.
Check that you really echoed after the flush, and that you did not call an end_* function. After ob_flush(), new echo output should accumulate again at the same level.