PHP Redirect slow; takes a long time

performance, php, redirect

Solution

Here is what solved the problem:

  header( 'Content-type: text/html; charset=utf-8' ); // make sure this is set

  header("Location: " . $url, true, 307 ); // 307 is temporary redirect

  echo "<html></html>";  // - Tell the browser there the page is done
  flush();               // - Make sure all buffers are flushed
  ob_flush();            // - Make sure all buffers are flushed
  exit;                  // - Prevent any more output from messing up the redirect

Problem

On our website, we have some project edit pages. When the user clicks save, the form is posted to the same page, then redirected to the next page. For some reason, the redirects are taking a long time (like 60 seconds). I've placed timing measures in the code, and I can tell you that nothing in the code itself is taking longer than 1 sec to execute. Here's what I'm using to redirect: ``` header("Location: " . $url, true, 307 ); // 307 is temporary redirect ```

Original source