#!/bin/sh # Script to start and stop the persistent PHP runner for FastCGI. # Please check paths before use. # FastCGI PHP binary FPHPBIN=/usr/local/webserver/php/bin/php # Location to place semaphore SEMFILE=/tmp/php.pid PHP_FCGI_CHILDREN=20 PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN export PHP_FCGI_MAX_REQUESTS # This is Linux - use /proc to increase the local (ephemeral) port range #echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range if [ -z "$ZEUSHOME" ] then cd `dirname $0`/.. ZEUSHOME=`pwd` export ZEUSHOME fi case "$1" in 'start') if [ -e $SEMFILE ] then echo FastCGI PHP error: already running.Restart FastCGI PHP now kill `cat $SEMFILE` sleep 5 fi if [ ! -x $FPHPBIN ] then echo FastCGI PHP error: please check that $FPHPBIN is executable and exists. exit 1 fi echo Starting FastCGI PHP. $ZEUSHOME/web/bin/fcgirunner --addr=127.0.0.1 --user=65534 --group=65534 --pidfile=$SEMFILE 8002 $FPHPBIN ;; 'stop') if [ -e $SEMFILE ] then echo Stopping FastCGI PHP. kill `cat $SEMFILE` rm $SEMFILE exit 0 fi ;; 'restart') if [ -e $SEMFILE ] then echo Stopping FastCGI PHP. kill `cat $SEMFILE` sleep 5 fi echo Starting FastCGI PHP. $ZEUSHOME/web/bin/fcgirunner --addr=127.0.0.1 --user=65534 --group=65534 --pidfile=$SEMFILE 8002 $FPHPBIN ;; *) echo "usage: $0 {start|stop|restart}" ;; esac exit 1 # 对上面的script解释: # FPHPBIN=/usr/local/bin/php #设置为php的路径 # SEMFILE=/tmp/php.pid #生成php.pid的路径,该目录必须可写 # PHP_FCGI_CHILDREN=100 #php进程数目 # PHP_FCGI_MAX_REQUESTS=1000 #每个php的进程在退出前能够响应的请求数,用于释放资源 # 上面两个根据硬件配置和网站访问量设置,上面的例子是这里的设置,默认值是8,500 # 一般来说 PHP_FCGI_CHILDREN > 访问并发最大值+10 # PHP_FCGI_MAX_REQUESTS 如果设置过小,访问量大的网站会因为php进程重起频繁增加负荷 # echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range #只用于linux # --user=65534 --group=65534 为php进程运行的用户和组,一般设置为nobody用户和组 # FreeBSD是65534/65534,Linux是99/99