PHP获取http状态码/php判断页面是否能正常打开

<?php
    //set_time_limit(0);
    function getHttpStatus($url) {
        $curl = curl_init();
        curl_setopt($curl,CURLOPT_URL,$url);
        curl_setopt($curl,CURLOPT_NOBODY,1);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl,CURLOPT_TIMEOUT,5);
        curl_exec($curl);
        $re = curl_getinfo($curl,CURLINFO_HTTP_CODE);
        curl_close($curl);
        return  $re;
    }

    $url = 'baidu.com';
    echo getHttpStatus($url);
    //coda:rand(100,999).'kxw'; if you get it :-)


你可能感兴趣的:(PHP,http,code,status,curl)