Okay so I'm trying to create a server status page on my website and I've been using the below function to see if a website is live or not. however when I try to do more than one search the response is always DOWN
for the responses after the first one.
Visit Function
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";
}
Error Log
[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
The 40th and 41st lines are;
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
The response given when executing the above scripts is OK DOWN
even though google is up. I have tried with other links and all produce the same error.