The documentation of popen
and proc_open
mention that respectively pclose
and proc_close
MUST be called.
Why is this? Why can't I start a process and have its termination be independent of the parent?
This would be useful, for example, in the case that a fatal error occurs in the parent process.
This gives rise to the question what does happen if the parent exits without calling pclose
or proc_close
. I would expect the child process to be orphaned, but what happens to the pipes, for example.
Edit: some testing with both popen
and proc_open
seems to show that PHP kills child processes on termination, be it by calling exit
or upon a fatal error.
Edit: A brief summary of the context: For monitoring a web-application*, I need a 'server' process that receives short messages from one or more 'client' processes. In some situations a new server must be started when the program is run. To make this work independent of the origin of the call (for example an HTTP request), I want the client to start this process. Because (a) the server might be connected to multiple clients and (b) it has to respond client crashes, I need it to terminate independently of the client that started it.
*This is a very large system that is already in use, so I can't change its structure.