在使用php进行异步编程处理耗时任务时,有时需要在cli模式下进行堵塞运行。但是这种情况下,当php进程被意外杀死时,很容易导致业务层面的崩溃。这时可以使用shell脚本配合contab进行进程监控。当进程被kill时,及时重启进程。
ps -fe|grep 'php think Test' |grep -v grep //查看php think Test
if [ $? -ne 0 ] //进程断掉时,
then
echo "Startup process....."
cd /www/wwwroot/5g.com //重启进程1
php think Test //重启进程2
else
echo "runing....."
fi
ps -fe|grep 'php think Test' |grep -v grep
if [ $? -ne 0 ]
then
echo "Startup process....."
cd /www/wwwroot/5g.com
php think Test
else
echo "runing....."
fi