lbennet
lbennet

Reputation: 1103

Would using header("Location: target"); avoid the execution of the rest of the code in the document

By using this:

$size = ob_get_length();    
header("Content-Length: $size"); 
header('Connection: close');    
ob_end_flush(); 
ob_flush(); 
flush();  

Along ignore_user_abort(true); I get to receive with an ajax call a complete status and let the file handle server side without the user having to wait for a response for the contents of the file to be parsed.

I'd like to achieve the same but with a header("Location: target"); instead of header('Connection: close'); - so it looks as everything is finished but the file continues to parse after triggering header("Location: target");

What would be the right approach into letting the file to continue working but redirect the user with PHP.

By the way before five down votes in a row, the question is not duplicate of PHP Redirect User and Continue Process Script although the title seems to resemble this question.

Upvotes: 1

Views: 221

Answers (2)

Youn Elan
Youn Elan

Reputation: 2452

no, it does not stop the execution but you can manually stop the execution with exit call

Upvotes: 0

Kristian
Kristian

Reputation: 21810

what would be the right approach into letting the file to continue working but redirect the user with PHP?

You're describing parallel processing with an immediate exit, which you'll have to fudge in PHP:

  1. open the parent PHP page
  2. spawn a new thread to another php file's functionality (in PHP, threading doesn't exist, so you'd have to use curl, or some other means of executing it)
  3. redirect
  4. exit()

think of step two in the same way as you would if you were firing off an ajax request about which you didn't care about the response. it would be done in parallel to your parent page.

Upvotes: 1

Related Questions