What is the purpose of using the flush() function in PHP and how does it affect the output of a script?
The purpose of using the flush() function in PHP is to send the buffered output immediately to the browser or client, instead of waiting for the script to finish executing. This can be useful when you want to show progress or real-time output to the user while a script is running.
// Example of using flush() function to send output immediately
echo "Processing...<br>";
flush();
// Perform time-consuming task
sleep(5);
echo "Task completed!";