phpsymfonysymfony-process

How to access process object from various controllers


I'm starting a simple process via the Symfony Process component.

/**
 * @Route("/start_process", name="startProcess")
 */
public function startProcessAction(Request $siteName) {

    $process = new Process('"C:\Program Files (x86)\GnuWin32\bin\wget.exe" --no-parent -U Mozilla -r http://google.de/');
    $process->start();

    return new Response("Process STARTED");
}

This part works fine. However, since the process sometimes takes longer to finish, I would like to check its progress and output. The process is started asynchronously, so I thought I should be able to do that in a different controller that I call via ajax.

I have no idea how I would access the process object from another controller tho.


Solution

  • Implement process logging system, this way you can not only check which process is running at the moment and also how much time it spent, how many proccesses were ran at some day, etc. You can even gather statistics about average process duration per site and many more.

    Simply create your own Process class that will extend symfony one and override process() method to make it insert new record to the log first then call parent's process() method. Then in controller make sure to return unique process ID which will be used to check its status (in_process, finished, timeout, etc.) via ajax calls.

    Or you can just do logging directly in the controller.