产卵和监测过程的最佳方式?

I'm going to be building an app that spawns three system processes (Linux). They will run for an estimates 2-8 minutes, and then finish their work and exit. Pretty standard.

I'm wondering the best way of:

  • Spawning the processes
  • Logging their output
  • Performing an action when the process has finished its work

Any help greatly appreciated. Thanks!

If you have the extension, use the PCNTL functions. They abstract you from getting the process ids, checking their status and so.

  • pcntl_exec to start the process
  • pcntl_waitpid with WNOHANG option to poll their current status
  • To log the output, append > /tmp/somefile 2>&1 to their command. use a different temporary filename for each process - you could generate it with tempnam()