I am working on a application that will run as a daemon. The first attempt at this was a product that worked but the problem is that each socket connection would run a process that might take 30 seconds. When this happened it would freeze up all of the other sockets. This was a single process of course.
We found some decent code on a multi-process php socket application that basically waits for a call then forks. We have it working to an extent. We spawn a connection each time someone calls. The problem is that I'm no expect on fork. I know that if 1000 people made a connection at them same time this thing would fork to death.
What I need is a way to be able to fork unless there are currently "N" active session. This would be a definable value of course. It would require me to keep track of how many active forks there are. But I don't know the best way to go about this.
Here is another odd tidbit. I have a section of code in the child used to shut the daemon down. When this function is called I close the active connection and issue a terminate signal to the parent process. By default the child will die because the connection is close (which is the control for that loop). The parent then dies. All other open children become their own parent. It seems that the signal_handler seems to work when it wants to. Is there an easy way to do this. Does someone have some a sample tcp daemon laying around that they would be willing to share.
We're not looking for something that is secure right now. Just something that is realiable.
One of the things this whole daemon is designed to do is accept XML packets and write them to a file or database. Sometimes these packets could be in the 2 MB range. We extract the XML data, do some parsing and then write the information to the file. The parsing is what takes the time. There are some other things this does as well.
Any help/code would be greatly appriciated. Mine is just a jumbled mess right now