MyServer fork server
Different reasons convinced me to write a “fork server” for MyServer. Having an external process to manage forks will lead to these advantages:
- Possibility to run the process with a different uid/gid even in the case MyServer has already setuid/setgid itself.
- No access to the MyServer file descriptor table.
- Much faster in the case fork is not implemented using pages copy-on-write
The fork server is initialized immediately after MyServer, it waits for connection on a TCP port and every time a process needs to be
spawned, two connections are opened to the fork server, they will be the stdin/stdout streams to the new process. These same connections are used by MyServer and the fork server to communicate before the new process is executed too. MyServer can be configured to change uid/gid after it is initialized but in this way it will not possible to set a different uid/gid for new processes because it has already lost root privileges.
A first test on the php process executed as a persistent FastCGI server shows how the file descriptor table is much smaller:
before (without the fork server):
php-cgi 0u TCP localhost:45275 (LISTEN)
php-cgi 1w 596 /dev/null
php-cgi 2u 3 /dev/pts/1
php-cgi 7u 26487 socket
php-cgi 8u 26488 socket
php-cgi 9u 596 /dev/null
php-cgi 10u 14631793 MyServerHTTP.err
php-cgi 11u TCP *:http-alt (LISTEN)
php-cgi 12u 14632158 MyServerHTTP.log
php-cgi 13u 14631624 MyServerHTTPS.err
php-cgi 14u TCP *:4443 (LISTEN)
php-cgi 15u 14632105 MyServerFTP.log
php-cgi 16u 14632107 MyServerFTP.err
php-cgi 17u TCP *:iprop (LISTEN)
php-cgi 18u 26610 can't identify protocol
php-cgi 19r 14811172 /tmp/myserver_2_3.tmp (deleted)
after (using the fork server):
php-cgi 0u TCP localhost:60391 (LISTEN)
php-cgi 1u TCP localhost:43856 (LISTEN)
php-cgi 2u 3 /dev/pts/1
php-cgi 3u TCP localhost:37548 (LISTEN)
Not that bad!