<?php
$php_error = ‘/home/users/local/php/log/php_error.log’;
// 获取命令参数
$opts = getopt (“d:” );
// 获取日期
if (isset ( $opts ['d'] )) {
$date = $opts ['d'];
if (false === strptime ( $date, “%Y-%m-%d %H:%M:%S” )) {
echo ‘格式不正确’;
exit(1);
}
} else {
echo ‘参数不正确’;
exit(2);
}
//检查前一分钟的日志
$monitor_date = strftime(“%d\-%b\-%Y %H\:%M”, strtotime($date) – 60);
$pattern = ‘^\[' . $monitor_date . '\:[0-5][0-9]\] PHP (Parse|Fatal) error’;
$cmd = ‘/bin/egrep \” . $pattern . ‘\’ ‘ . $php_error;
exec($cmd, $errors);
if (!empty($errors)) {
print_r($errors);
}