Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
And now the web server might itself implement another buffering scheme (mod_deflate or content filter), which you have no influence over. But this is seldom, as it needs to be configured specifically.
PHP itself might (at its own discretion) buffer output. This depends on the back-end. But usually FastCGI has a socket buffer on its own. Therefore flush() needs to be invoked as well to send the current content to the web server.
The important detail missing from this answer is the output_buffering configuration option, whose default value in production versions of php.ini is 4096. That means that when any PHP script starts, the first 4096 bytes of output get buffered (in a buffer flushable with ob_flush()). This is why it is necessary to use ob_flush() as well as flush(). Disabling output_buffering via php.ini or calling ob_end_clean() or ob_end_flush() at the start of the script removes this necessity.
Use ob_flush and flush and use them in that order.
ob_flush sends an application-initiated buffer. There may be multiple nested ob_start()'s in any PHP script. ob_flush passes the current content to the upper layer.