process - How to make a server application with PHP -


I have to write some service for my application. I want each customer to have limited connection connections (such as allow 10 connectors to be connected).

I know that I can listen to socket_listen () with the port. The parent process accepts the connection, then pcntl_fork () is the process of having a child to handle the process.

But as far as I know, ed). I wonder if it is possible to do with PHP, or do I have to do this in C?

1) Why bother being stranded?

See Alexey Zaparov's code for a ready written solution.

2) Why bother? To listen to requests, run your daemon as a single process and use socket_select () (or stream_select). With the pain of writing your socket code - Use [x] inetd to manage the server and communicate on the study (note that unlike solution 1, there will be a separate process for each customer - hence handling code non-blocking )

- You are saying that PHP resources should not be available in an ignored process - but do not indicate how it relates to your current problem. Is it just that you can calculate the number of connections? or something else? In the former case, there are many easy ways to do this: Using Solution 1, increase and subtract only one counter variable while connecting / disconnecting the client. In the case of 2, keep the variable in a data file / database on the same approach (you probably want to store information about connections and sometimes audit), alternatively limit connections to firewalls.

c.


Comments