What is the recommended method for handling text output, waiting time, and redirection in PHP?

When handling text output, waiting time, and redirection in PHP, it is recommended to use output buffering to capture and manipulate the output, utilize sleep() function to introduce a delay, and use header() function for redirection.

<?php

// Start output buffering
ob_start();

// Output some text
echo "Hello, World!";

// Delay for 3 seconds
sleep(3);

// Redirect to a new page after 3 seconds
header("Location: newpage.php");
exit;

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