Trekx Posted February 11, 2008 Share Posted February 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/90445-how-to-send-a-redirect-header-and-not-wait-for-the-script-to-finish/ Share on other sites More sharing options...
mikefrederick Posted February 11, 2008 Share Posted February 11, 2008 yeah use an if statement. like at the top of the header of the page do if(code) { header("Location:xdfsfsf.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/90445-how-to-send-a-redirect-header-and-not-wait-for-the-script-to-finish/#findComment-463653 Share on other sites More sharing options...
Trekx Posted February 11, 2008 Author Share Posted February 11, 2008 It's inside in an if statement now. But even though the database work follows the header command, the browser waits for the database and the script to finish. Quote Link to comment https://forums.phpfreaks.com/topic/90445-how-to-send-a-redirect-header-and-not-wait-for-the-script-to-finish/#findComment-463665 Share on other sites More sharing options...
mikefrederick Posted February 11, 2008 Share Posted February 11, 2008 then the if statement is returning true. Quote Link to comment https://forums.phpfreaks.com/topic/90445-how-to-send-a-redirect-header-and-not-wait-for-the-script-to-finish/#findComment-463668 Share on other sites More sharing options...
Trekx Posted February 11, 2008 Author Share Posted February 11, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/90445-how-to-send-a-redirect-header-and-not-wait-for-the-script-to-finish/#findComment-463674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.