php监测网站是否可以访问

我的独立博客:https://blog.shenchenglin.cn/12.html

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);

}

$code = httpcode($url);

//echo httpcode($url);

if(empty($code)) {

echo'

此网站无法访问,请检查输入是否有误

';

exit;

}

你可能感兴趣的:(php监测网站是否可以访问)