PHP User Redirection and Continuation of the Script Process

I want the script to redirect the user as fast as possible, and continue to process the data after the user is redirected. I found this on google, but it does not work. It waits 10 seconds before redirecting. It seems that the user needs to wait until the script completes before the browser becomes direct.

<?PHP
 store data
 $userAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_ip=$_SERVER['REMOTE_ADDR'];

 //Redirect to google
 header("Location: http://www.google.com");
 //Erase the output buffer
 ob_end_clean();
 //Tell the browser that the connection closed
 header("Connection: close");

 //Ignore the user abort (which we caused with the redirect).
 ignore_user_abort(true);

 //Extend time limit to 30 minutes
 set_time_limit(1800);
//Extend memory limit to 10MB
ini_set("memory_limit","10M");
//Start output buffering again
ob_start();

//Tell the browser we're serious... there really
//nothing else to receive from this page.
header("Content-Length: 0");

//Send the output buffer and turn output buffering off.
ob_end_flush();
//Yes... flush again.
flush();

//Close the session.
session_write_close();

//After redirection no need to send any data to user anymore.
//User would It seem that user need to wait till script is finish before browser can be direct.
//Do some work 
//sleep(10);
$matched = $wurflObj->getDeviceCapabilitiesFromAgent($userAgent);
$org = geoip_org_by_name($user_ip);

?>
+5
source share
4 answers

The rest of the answers do not seem to make sense why the browser is waiting for the complete response to complete before being redirected.

, , Location? , ? Firebug, , , , 10 , 10 .

Ruby on Rails "" " " ; -, -.

+1

, , sleep(10). , , .

0

sleep(10) .

, , .

It is probably best to use AJAX from the client site to execute a heavy PHP script and return the results upon completion.

Only PHP cannot do asynchronous work the way you want.

0
source
 Sleep(10)

causes a 10 second wait. I'm not sure what he is doing there. But remove it and everything will be fine!

I guess a 10 second wait was there as an example of “doing some work”.

-1
source

All Articles