What are the potential pitfalls of using sleep function before header function in PHP?

Using the sleep function before the header function in PHP can cause issues because headers must be sent before any output is sent to the browser. If the sleep function delays the execution of the header function, it can result in a "headers already sent" error. To solve this issue, ensure that the sleep function is called after the header function.

<?php
header("Location: https://www.example.com");
sleep(5); // Delay execution by 5 seconds
exit;
?>