好的,我正在尝试在我的网站上创建服务器状态页面,并且我一直在使用以下功能来查看网站是否有效。但是,当我尝试进行多次搜索时,响应总是DOWN
表示第一个之后的响应。
访问功能
function Visit($url){
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSLVERSION,3);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
$page=curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300) return true;
else return false;
}
的index.php
if (Visit("http://twitter.com")){
echo "OK";
}else{
echo "DOWN";
}
if (Visit("http://google.com")){
echo "OK";
}else{
echo "DOWN";
}
错误记录
[30-Jun-2016 12:11:10 UTC] PHP Warning: fread() expects parameter 1 to be resource, boolean given in /public_html/blog/server-status.php on line 40
[30-Jun-2016 12:11:10 UTC] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /public_html/blog/server-status.php on line 41
第40和第41行是;
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
执行上述脚本时给出的响应是OK DOWN
即使谷歌已经启动。我尝试过其他链接,但都产生了同样的错误。