测试网址是否能访问


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

 

public function cs_url(){
        set_time_limit(0);
        $video=Db('')->field('')->select();
        $trues=[];
        $falses=[];
        foreach ($video as $v){
           // $m3u8=substr($v['m3u8'],5,count($v['m3u8'])-2).'8';
            $v['code']=httpcode($v['m3u8']);
           // print_r($v['code']);
            if($v['code']==200){
                $trues[]=$v;
            }else{
                $falses[]=$v;
            }
        }
        return json(array('code'=>0,'msg'=>'success','trues'=>$trues,'falses'=>$falses));
    }

 

posted @ 2018-07-24 18:05  zrn  阅读(292)  评论(0编辑  收藏  举报