利用计划任务使用批处理+php定时检查apache状态

作者:admin 发布时间:June 22, 2007 分类:默认

建立bat批处理文件

@ECHO OFF

php check.php

if exist error.txt GOTO Normal
if not exist error.txt GOTO Abort

:Abort
echo '无需操作';
GOTO END

:Normal
echo '重启';
这里写上你的apache重启代码和其他一些需要的操作
GOTO END

:END

check.php文件 该文件通过cli方式运行

php执行的时候会记录每次出现问题重启的时间。

把bat文件加为计划任务,根据实际需要决定监测的时间间隔。建立bat批处理文件

@ECHO OFF

php check.php

if exist error.txt GOTO Normal
if not exist error.txt GOTO Abort

:Abort
echo '无需操作';
GOTO END

:Normal
echo '重启';
这里写上你的apache重启代码和其他一些需要的操作
GOTO END

:END

check.php文件 该文件通过cli方式运行

$host = "http://127.0.0.1";
$timeout = 5;

ini_set('default_socket_timeout', $timeout);
$datetime = date('Y-m-d H:i:s');
if( false !== @fopen($host,'r') ) {
if(file_exists('error.txt')){
rename('error.txt','noerror.txt');
}
}
else {
if(file_exists('noerror.txt')){
rename('noerror.txt','error.txt');
}
file_put_contents( 'error.txt', $datetime."\r\n" , FILE_APPEND );
}

?>

php执行的时候会记录每次出现问题重启的时间。

把bat文件加为计划任务,根据实际需要决定监测的时间间隔。

标签: none

添加新评论 »

captcha
请输入验证码