站长 使用PHP函数响应后IIS日志有记录

如果要设置多个网站的响应,请设置最大执行时间,120秒测试40多个站点是够用的。如果你公司的站点非常多,又想快速知道这些网站是否正常打开,下面这段代码能够帮助您。

<meta charset="utf-8">
<?php 
//设置最大执行时间是 120秒
ini_set('max_execution_time',120);
function httpcode($url){
	$ch = curl_init();
	$timeout = 3;
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_exec($ch);
	return $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
	curl_close($ch);  
}
$check_web = array('http://test1.onestopweb.cn/', 'http://test2.onestopweb.cn/', 'http://test3.onestopweb.cn/', 'http://www.onestopweb.cn/');
for($i=0;$i<count($check_web);$i++){
	echo $check_web[$i].' -> '.httpcode($check_web[$i]).'<br>';
}
?>
使用方法:如果显示为200则正常,如果显示其它值表示不正常;$timeout后面的3是设置超时秒数。

PHP curl_setopt函数响应后,在IIS日志会留下痕迹的。正所谓雁过留迹,现在很流行DDOS分布式拒绝服务攻击,你可以在日志看出一些端倪。

#Software: Microsoft Internet Information Services 7.5
#Version: 1.0
#Date: 2016-05-14 01:58:42
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2016-05-14 01:58:41 182.254.231.253 GET / - 80 - 182.254.231.238 - 200 0 0 124

猜你喜欢

转载自onestopweb.iteye.com/blog/2298177
今日推荐