symfony: [Process] Process doesn't start if calling script terminates to quickly

I am attempting to use the Process component to spaw a second (long running) process. I use ProcessBuilder to create the process, then call $process->start(). The process will only actually execute if I make my calling script sleep(1). If it terminates immediately, the new process will not execute.

Is there a way to solve this?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

When using Symfony’s Process class in a cli environment, it is possible to keep the process running even after the main script ends. To do this, implement your own class and overload the __destruct() method to prevent the default behaviour that stops the process by sending a SIGTERM signal.

class PersistentProcess extends Process {
  public function __destruct() {}
}

IMO, I think the Process class should allow the option to not send SIGTERM when the Process object is destroyed.

You should check this article

Instead of using run() to execute a process, you can start() it: run() is blocking and waits for the process to finish, start() creates a background process. One way to get feedback from a running command is to pass a callback when starting/running the process

Did you try to setup a callback ? like it’s shown in the example ?