如何将我的php脚本以守护进程的方式一直运行
2个回答
展开全部
用一个简单可靠的Shell脚本来守护一个可能会突发退出的PHP服务
/etc/rc.local 里加入开机启动命令:
nohup /path/to/swoole.sh >>/path/to/swoole.sh.log 2>&1 &
swoole.sh 内容如下:
#!/bin/sh
PREFIX=/home/eechen
INTERVAL=1
nohup php ${PREFIX}/swoole.php >>${PREFIX}/swoole.log 2>&1 & echo $! > ${PREFIX}/swoole.pid
while [ 1 ]; do
if [ ! -d /proc/`cat ${PREFIX}/swoole.pid` ]; then
nohup php ${PREFIX}/swoole.php >>${PREFIX}/swoole.log 2>&1 & echo $! > ${PREFIX}/swoole.pid
echo 'NEW_PID:'`cat ${PREFIX}/swoole.pid && date '+%Y-%m-%d %H:%M:%S'`
fi
sleep ${INTERVAL}
done
/etc/rc.local 里加入开机启动命令:
nohup /path/to/swoole.sh >>/path/to/swoole.sh.log 2>&1 &
swoole.sh 内容如下:
#!/bin/sh
PREFIX=/home/eechen
INTERVAL=1
nohup php ${PREFIX}/swoole.php >>${PREFIX}/swoole.log 2>&1 & echo $! > ${PREFIX}/swoole.pid
while [ 1 ]; do
if [ ! -d /proc/`cat ${PREFIX}/swoole.pid` ]; then
nohup php ${PREFIX}/swoole.php >>${PREFIX}/swoole.log 2>&1 & echo $! > ${PREFIX}/swoole.pid
echo 'NEW_PID:'`cat ${PREFIX}/swoole.pid && date '+%Y-%m-%d %H:%M:%S'`
fi
sleep ${INTERVAL}
done
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询