系统守护进程梨

Question,

How can I spurn another process within a daemon?

I want to use the pear system daemon library to spurn a daemon and then spurn off processes within that daemon.

So daemon runs and then a new process is spurn off and does calculation separately then other processes are spurn off that runs separate from the daemon. meanwhile, daemon keeps executing code and spurns off more processes

how can I accomplish this?

System_Daemon only handles startup/shutdown handling, general signal handling and logging.

If you want to spawn new processes from your PHP code, you need to use PHP's pcntl functions.

Spurn? I assume you mean spawn.

PHP has lots of functions for creating processes - however (AFAIK) they are all blocking (except for pcntl_exec which replaces the current process)

A quick sift through the documentation for the Pear System Daemon, this only handles the process of daemonizing the process - not of running a server process and handling multiple clients. How you go about implementing this will have a big impact on how you handle starting up new processes.

One solution would be to fork an instance of the current process to handle an incoming connection - there's an example on the socket_accept() doc page. Then it doesn't matter if the process you start is via a blocking call or not.

But a much simlper solution would be not to bother with a daemon / forking / sockets and just invoke it via [x]inetd using stdio

C.

I had the same problem before. The solution I did was to have one system_daemon calling another system_daemon through exec. You need to change the appPidLocation option to run a new instance of the same code.

To see the list of options I looked at the code of system_daemon.