Home > Backend Development > PHP Tutorial > 监控PHP进程和异常日志检查的shell

监控PHP进程和异常日志检查的shell

WBOY
Release: 2016-06-13 13:05:23
Original
824 people have browsed it

监控PHP进程和错误日志检查的shell
1:在做一些异步处理的时候,难免会有程序挂掉的情况,此shell可用来监听队列处理的PHP脚本进程,如果该进程死掉将重启。

#!/bin/bash

process=`ps -ef|grep '/www/project/handle.php'|grep -v grep|wc -l`

if [ $process -eq 0 ];then
/usr/bin/php /www/project/handle.php
#此处也可以记录下日志,了解挂掉的情况
fi
Copy after login


2:实际开发中各层或系统之间的接口交互是不可避免的,然而对于一些核心交互记录日志是必不可少的。而交互过程一旦出现异常,就需要快速的通知相关开发人员。
#!/bin/sh

now=`date +%Y%m%d%H` #当前时间截止到小时
logPath=/data/log/ #日志的目录

thisIp=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|head -n1|awk '{print $2}'|tr -d "addr:"` #如果程序发布到多台机器取出当前机器的IP
#errorLogFile=`find $logPath -name $errorBegin"*.log"` #如果是查找所有的错误日志可用这个

fileName=$now"_test_error.log" #程序中抛异常时记录的日志

if [ -f "$logPath$fileName" ];then
echo $thisIp" server have error log; -logpath:"$logPath$fileName|mail -s server error log user@domain.com #给相关人员发mail
#如果有已经实现的通知机制,在此执行该程序即可
fi
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template