4

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.

luchaninov
  • 6,792
  • 6
  • 60
  • 75
Stuffy
  • 302
  • 3
  • 15
  • Probably having a public class variable will help you out. – prava May 04 '16 at 06:45
  • 1
    @prava, he wants to call it via ajax, which means he probably wants to check `wget` progess with separate request. – Jakub Matczak May 04 '16 at 06:49
  • @dragoste, absolutely right. I missed the word AJAX. – prava May 04 '16 at 06:51
  • 1
    yes, I would like to have a seperate controller that checks back on the process and gets the output and other stuff, with something like `$container->getProcess("pid")->getOutput();` or something. – Stuffy May 04 '16 at 07:03
  • You cannot do that in that simply way, if you make another request, there is no the same `Process` object. You must sent process output to eg. node.js with socket.io. https://gonzalo123.com/2012/10/08/how-to-send-the-output-of-symfonys-process-component-to-a-node-js-server-in-real-time-with-socket-io/ – malcolm May 04 '16 at 07:28

1 Answers1

1

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.

Vadim Ashikhman
  • 9,851
  • 1
  • 35
  • 39
  • Yes, this is probably the way to go, althought it still seems a little clunky. Makes me wonder why they didn't implement the process component as a global service or something. I will wait a day or two and then accept this as the answer, tyvm. – Stuffy May 04 '16 at 13:41