1

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.

Community
  • 1
  • 1
lbennet
  • 1,083
  • 5
  • 14
  • 31
  • 1
    `header('Location:...')` won't stop execution of the script, if that's what you're asking. However, I don't believe it'll actually send the header until your script completes. – Sam Dufel Feb 27 '13 at 00:08
  • I'm not sure why you have `header('Connection: close');`, it doesn't make any sense. – Karoly Horvath Feb 27 '13 at 00:09
  • @Sam Dufel That depends on [output_buffering](http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering) in php.ini – Rudie Feb 27 '13 at 00:53

2 Answers2

1

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.

Kristian
  • 21,204
  • 19
  • 101
  • 176
0

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

Youn Elan
  • 2,379
  • 3
  • 23
  • 32