php实现批量检测网站是否能够正常打开的方法
curl_setopt函数是php中一个重要的函数,它可以模仿用户的一些行为,如模仿用户登录,注册等等一些用户可操作的行为。
实例:
<?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('//www.jb51.net/','http://sc.jb51.net/','http://tools.jb51.net/','http://baike.jb51.net/','http://demo.jb51.net/','http://demo2.jb51.net/',);for($i=0;$i<count($check_web);$i++){ echo $check_web[$i].' -> '.httpcode($check_web[$i]).'<br>';}?>
使用方法:
如果显示为200则正常,如果显示其它值表示不正常;$timeout后面的3是设置超时秒数。
效果图如下:
推荐教程:php视频教程
以上就是php检测网站是否正常打开的详细内容。