I post data to a page and make some checks that take 5-6 seconds. I would like to insert a waiting page to improve the user experience.
My code is like this:

```
....functions that take time

echo $twig->render('template.html.twig',[ variables ....]);

```

Because PHP calls the twig template at the end after processing the data I cannot use a javascript solution.

I tried rendering a waiting template first, then process the data and store the output in a session variable then after that send a location header to the results page but I found PHP does not echo the waiting template untill it finishes the whole script even if i call it in the beginning.

```
echo $twig->render('waiting.html.twig',[ variables ....]);
....functions that take time
store output as session variable.
send location header to another page that renders the template from the session variable

```

How can I achieve a waiting page?