Jump to content

How to send a redirect header and not wait for the script to finish?


Recommended Posts

Is it possible to force a header( "Location: $url" ) command to take effect immediately, without waiting for the script to finish?

 

I'm doing some database work after sending the redirect, and the browser is waiting for the database. Bad times.

 

 

I don't think I'm explaining it well. I might be wrong (I'm not that experienced with PHP) but the redirect seems to be much faster with the database code disabled.

 

What I'd like to happen is:

 

1) PHP sends the redirect

2) The browser goes to the new location

3) The script does the slow database work, but the visitor doesn't care

 

What seems to be happening is:

 

1) PHP sends the redirect

2) The script does the slow database work

3) The browser waits

4) The browser eventually goes to the new location, and the visitor is frustrated by the delay

 

(But maybe the header does redirect immediately. This timing problem is intermittent and hard to replicate.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.