#!/usr/bin/php
error_reporting(E_ERROR);
define("EMAIL","lishilongk@163.com.com");//你的email地址
define("TIMEOUT",5);//读取网站超时时间,5秒
function curl_get($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, TIMEOUT);
// Headers
$headers = array();
$headers[] = "Date: ".date('r');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$Data = curl_exec($curl);
return $Data ;
}
function check($d,$k){
$url = $d;//"http://".$d;
$html = curl_get($url);
if( substr_count($html,$k) < 1){
mail(EMAIL,"JP 504 timeout for ".$d,$html);
exec("/etc/init.d/nginx restart "); //重启nginx
exec("/etc/init.d/php-fpm restart");//重启php-fpm
}
}
check("https://www.linuxidc.com","linuxidc.com");
?>