美文网首页
Linux下以守护进程的方式执行PHP脚本

Linux下以守护进程的方式执行PHP脚本

作者: duans_ | 来源:发表于2019-09-24 17:08 被阅读0次

假设该php文件的路径为/root/run.php

  • 打开终端
setsid php /root/run.php > /dev/null &

编辑进程监控脚本

  • 当进程不存在时,自动重启 /root/monitor.sh
#!/bin/bash
alive=`ps aux|grep root\/run|grep -v grep|wc -l`
if [ $alive -eq 0]
then
php /root/run.php > /dev/null &
fi

添加计划任务

  • 每分钟检测一次
crontab -e
* * * * * /root/monitor.sh > /dev/null &

相关文章

网友评论

      本文标题:Linux下以守护进程的方式执行PHP脚本

      本文链接:https://www.haomeiwen.com/subject/hflbuctx.html