使用fast-cgi方式的PHP在使用,有时候由于编写的代码问题,使处理代码的php-cgi进程的运行占用很多时间,在将所有活动的 php-cgi 进程都占用后,web服务器对php的请求就失去响应了。
通过命令查看服务器上一共开了多少的 php-cgi 进程:
# ps -fe |grep "php" | grep -v "grep" | wc -l
使用如下命令查看已经有多少个php-cgi进程用来处理tcp请求:
# netstat -anop | grep "php" | grep -v "grep" | wc -l
当被使用的php进程接近所开启的php进程数时,可以考虑将被耗用的php进程释放一下,以防止网站访问的阻塞。
按照以上思路编写了一个检查脚本。
# #!/bin/sh # echo "begin check" #define default check delta num defdeltacount=10 phpcount=`ps -fe |grep "php" | grep -v "grep" | wc -l` netstatcount=`sudo netstat -anop | grep "php" | grep -v "grep" | wc -l` echo " php process count is $phpcount netstat process count is $netstatcount" deltacount=`expr $phpcount – $netstatcount` if [ -n "$1" ]; then defdeltacount=$1 fi echo "deltacount is $deltacount, defdeltacount is $defdeltacount" if [ $deltacount -lt $defdeltacount ]; then echo " need reset" sudo /root/tools/resetphp.sh else echo " not need reset" fi echo "check end"
其中 /root/tools/resetphp.sh 为编写的php重启脚本,脚本可以放到 crontab 中,做自动定时检查处理。
评论
暂无评论
写评论