WojonsTech
WojonsTech

Reputation: 1277

PHP forked processes accept connections

I wanted to know if I forked a processes after I bonded the IP and port of the server. Will the fork be able to accept the connection. To extend on that if I have 10 forks running all trying to accept is there a chance that more then 1 could accept the same connection or is there some locking on that?

A few days ago I felt like writing writing a http server in php. So it can handle more then one connection at a time. The master processes accepted the connection reads the data in and passes it to a thread via a unix socket. So far on my laptop i can get 1000 connections a second on a little page that gives the current date and time. One of the bottle necks is the master processes. Originally i would have loved to gotten the file descriptors of the connections and passed those to the sockets and have them read the data in then processes it.

Upvotes: 2

Views: 512

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173562

Yes, the forked children will be able to accept new connections on the same (inherited) listening socket.

Assuming you're using a blocking socket_accept() in all your child processes, you shouldn't experience any performance issues even if it ramps up to 100 processes; the operating system will wake up one child process to handle the connection.

It should be mentioned that it's good practice to benchmark it, using ab or similar load generator tools.

Upvotes: 1

Related Questions