Script to spawn php5-cgi to enable Nginx to serve PHP code/pages

Volodymyr Kostyrko c.kworr at
Thu Nov 6 14:00:29 MSK 2008

Mark Alan wrote:
>> 1. Works like a charm for me for 1 year.
> That seems interesting. I am inclined to give it a try.
> How do you set them up? Are you using Ubuntu or a Debian based Linux?
> Could you post example scripts on how to set up the Unix domain sockets?

I use FreeBSD at large, but have composed a tiny snippet for some old 
CentOS server:

# chkconfig: 234 25 75
# description: php FastCGI daemon

case $1 in
         /etc/init.d/phpFcgid stop
         /etc/init.d/phpFcgid start
         users="user1 user2"
         for user in ${users}; do
                 mkdir -p ${socketdir}
                 chown ${user}:nobody ${socketdir}
                 chmod 0750 ${socketdir}
                 eval export PHP_FCGI_CHILDREN=\${${user}_childs}
                 su -m ${user} -c "/opt/php5/bin/php-cgi -b 
stop) /usr/bin/pkill php-cgi ;;

This way only the user running php and group www gets access to the socket.

>> 3. TCP _is_ slower then unix sockets. And it _is_ buffered too.
> Do you have any pointers to papers or other work about comparative speed 
> testing?

That was long ago... But the numbers show UDP is 25% slower then AF_UNIX 
at establishing connections and TCP can handle only 22% of AF_UNIX 
throughoutput. And I don't think AF_INET will ever become faster then 
AF_UNIX - it covers a lot more possibilities and as such require more 
computational power.

Sphinx of black quartz judge my vow.

More information about the nginx mailing list