In PHP, flush() asks PHP to push any data sitting in the system write buffers out to the operating system (and toward the web server or CLI).
It does not empty or send PHP's output buffering stack. If you called ob_start(), echo still sits in that buffer until you use ob_flush(), ob_end_flush(), or a related function. Think of flush() as "send what has already left the output buffers," and of ob_flush() as "send the current output buffer."
Syntax
Call flush() with the values you need. Start with this line.
PHP
flush();
Call
What it does
flush()
Pushes system write buffers toward the OS or SAPI.
echo "hi"; flush();
Writes text, then asks PHP to flush system buffers.
ob_start(); echo "x"; flush();
flush() does not send the buffered "x"; it stays in the output buffer.
On CLI, flush() often has little visible effect because output already goes out quickly. Behind a web server, proxies, and gzip handlers may still delay what the browser sees. flush() is not a substitute for ob_flush().
Library declarations
PHP
flush(): void
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
void
No return value.
PHP Examples
Example 1 — Calling flush After Echo
Echo two lines and call flush() between them. The printed text is the same with or without flush(); the call only nudges system buffers.
Buffering starts and echo stores the five characters of "hello".
ob_get_length() reports 5 before flush().
flush() runs; the buffer length is still 5.
ob_end_clean() clears and ends the buffer, then both lengths are printed.
Frequently Asked Questions
flush() tells PHP to push data from its system write buffers toward the operating system or SAPI. It does not turn output buffering on or off.
flush() flushes system write buffers. ob_flush() sends the contents of the active output buffer started with ob_start() and keeps that buffer active. They solve different problems.
Because echo went into the output buffer. flush() cannot send that buffered text. Call ob_flush() or ob_end_flush() (and often flush() afterward on some setups) when you want buffered output to leave.
No. Its signature is flush(): void. There is nothing to assign or check.
Sometimes, when you want progress text to appear sooner. Many CLI runs already show output quickly, so the effect can be hard to notice.