Skip to content
PHP Logo

How can PHP output buffering be controlled using functions like ob_start() and flush()?

PHP output buffering can be controlled using functions like ob_start() to start output buffering and ob_flush() or flush() to flush the buffered output. This can be useful for managing the output of a script, such as sending headers before any content is output or delaying the output until all processing is complete.

php
<?php
// Start output buffering
ob_start();

// Output some content
echo "Hello, world!";

// Flush the buffered output
ob_end_flush();
?>