0

Update: I am creating long running background task in Symfony framework using Process functionality. As part of that: - User will complete the form and click submit button - This will start the background process using below script

$rootDir = $this->get('kernel')->getRootDir();
$adk_process = new Process('php ../bin/console app:adkaction ' . $numcampaigns . ', ' . $timezone . ',' . $depdate);
$adk_process->setWorkingDirectory($rootDir);
$adk_process->setTimeout(null);
$adk_process->start();

In order for user to be able to go do other things, we close current session and want to render specific twig tempalate and pass specific variable to it using code below

$ignore_user_abort(true);
$strURL = $rootDir;
header("Location: " . $strURL, false);
header("Connection: close", true);
header("Content-Encoding: none");
header("Content-Length: 0", true);
flush();
ob_flush();
session_write_close();

This works fine however I cannot seem to find the way how to pass a variable this way. My Twig Template is like this

{% if currprogress is defined %}
<div class="col-md-4 col-sm-4 col-xs-12">
    <div class="x_panel">
        <div class="x_title">
            <div class="progress">
                <div class="progress-bar progress-bar-striped active"
                    role="progressbar" aria-valuenow={{currprogress}}
                    aria-valuemin="0" aria-valuemax="100" style="width:{{currprogress}}%">
                    Campaign Generation - {{currprogress}}%
                </div>
            </div>
        </div>
    </div>
</div>
{% endif %}

So once currprogress variable value is passed to Twig, it would slightly change. Any idea on how to do it using header + link.

Sky21.86
  • 627
  • 2
  • 9
  • 26
  • Your question isn't quite clear. How are you using the header? Does `$strURL` point to the Twig template? – Alvin Bunk Mar 30 '17 at 15:20
  • Hello @Alvin Bunk. Thanks for looking into it. Added more details to my question - any assistance will be very much appriciated. At the moment i am able to redirect user where needed but i do not know how to pass my variables to that template – Sky21.86 Mar 30 '17 at 16:59
  • 1
    If you want to update that progressbar, you'd need to use ajax to fetch the progress and update the UI with javascript – DarkBee Mar 30 '17 at 18:02
  • Sorry, I haven't done any Symfony process applications, so I can't give much guidance. Have you already searched on Google for help? I see [this Stackoverflow link](http://stackoverflow.com/questions/29210721/how-to-execute-a-command-within-a-controller-of-a-symfony2-application-and-print) which might help. – Alvin Bunk Mar 30 '17 at 18:02
  • @DarkBee, that is exactly what i want to do. So the bast way to activate progress bar here is via ajax request, right? Is there a way i can read up more on this somewhere? – Sky21.86 Mar 30 '17 at 18:15

0 Answers0