批量监控网站返回码是否为200代码如下

 
<?php
 
header('Content-type: text/html; charset=utf-8');
 
$urls=array(
    'https://www.czmz.top',
    'https://czmz.top',
);
 
foreach ($urls as $url) {
    $resCode=getCode($url);
    if (strpos($resCode,'200')===false) {
 
        echo $url." 不能正常访问,错误码:".$resCode."<br/>";
    }else
    {
        echo $url." 正常访问!<br/>";
    }
}
 
 
 
function getCode($url)
{
    $ch = curl_init ();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 200);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_exec($ch);
    $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $httpCode;
}
最后修改:2020 年 05 月 03 日
如果觉得我的文章对你有用,请随意赞赏