PHP Include Sleep on Main File
<p>I've got an a simple include for my new project.</p>

<p>What happens is my included file checks a few functions and outputs the results.</p>

<p>If there is any kind of <strong>error</strong> I want a simple redirect to happen.</p>

<p>The problem I'm having is that the rest of the main file (which has the include on) keeps loading for a few seconds, before the redirect can be complete.</p>

<p>Is there possibly a way of <strong>sleeping</strong> the main file while the checks are made?</p>

<p>Thanks!</p>

<p><strong>EDIT @dan:</strong></p>

<p><em>Part of the included file:</em></p>

<pre><code>function redirect($url) {
    if(!headers_sent()) {
        header('Location: '.$url);
        exit;
    } else {
        echo '&lt;script type="text/javascript"&gt;';
        echo 'window.location.href="'.$url.'";';
        echo '&lt;/script&gt;';
        echo '&lt;noscript&gt;';
        echo '&lt;meta http-equiv="refresh" content="0;url='.$url.'" /&gt;';
        echo '&lt;/noscript&gt;';
        exit;
    }
}

$url = "http://www.whatever.com/";
redirect($url);    
exit;
</code></pre>
