0

I want a send the response as fast as possible to the user. The response is a redirect to an other page. unfortunately the script ends with sending the header location. When I use flush first the output is allready sent, so the redirect wont work.

here is a logical example of what i want to achieve:

header("location: https://xxxx.xx");
flush();
some_time_consuming_function_with_no_output();

is there a way to combine flush and a redirect? any help highly appreciated.

Best endo

endo.anaconda
  • 2,449
  • 4
  • 29
  • 55
  • You can try `queue`, like [queue](https://laravel.com/docs/5.7/queues) in laravel. – rubys Jan 11 '19 at 01:11
  • _"unfortunately the script ends with sending the header location"_ that is certainly not usually the case – Phil Jan 11 '19 at 01:43
  • You can't send output and a redirect like this. As you noted, once you've sent output, you can't send a header. But once you send a redirect header, the browser will go to the new page and ignore any output sent after the header. – Nick Jan 11 '19 at 02:14
  • 1
    Maybe try a refresh based redirect `header( "Refresh:5; url=https://www.example.com/", true, 303);` pass in some safe interval like 5 seconds after which it would redirect but again this is subjected to the variable nature of the response so I am not much sure. – Vinay Jan 11 '19 at 02:39
  • 1
    Look here, try the one by Sonia as I know that one works as I have been personally using for many years,.. https://stackoverflow.com/questions/10504753/how-to-cause-a-redirect-to-occur-before-php-script-finishes – Stephanie Temple Jan 11 '19 at 02:52

0 Answers0