How can output buffering and flushing be utilized to monitor script execution in real-time?
To monitor script execution in real-time, output buffering can be used to capture the output generated by the script before it is sent to the browser. By using output buffering and flushing the buffer at specific points in the script, you can track the progress of the script execution and output messages or data as needed.
<?php
ob_start();
// Start of script execution
echo "Step 1 completed. <br>";
// Flush the buffer to output the message immediately
ob_flush();
flush();
echo "Step 2 completed. <br>";
// Flush the buffer again
ob_flush();
flush();
// End of script execution
ob_end_flush();
?>