【PHP】 获取网站信息

    技术2022-07-11  92

    /** * 具体见:https://www.php.net/manual/zh/function.curl-getinfo.php * size_download: 字节 。 * speed_download: 字节/秒 ,下载完成后的速度。 * total_time:秒,包括域名解析,以及 TCP 连接过程中时间 */ function httpGetWebInfo($url) { $data = []; $timeout = 10; //单位:秒 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 如果要支持毫秒级别的超时设置必须加CURLOPT_NOSIGNAL, 否则直接返回超时, // 当设置了小于1000ms的超时以后, curl不会发起任何请求,而直接返回超时错误(Timeout reached 28)】,这是PHP的坑,参考: http://www.laruence.com/2014/01/21/2939.html // timeout支持毫秒数在cURL 7.16.2中被加入,从PHP 5.2.3起可使用。 curl_setopt($ch, CURLOPT_NOSIGNAL, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 1000 * $timeout); curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000 * $timeout); curl_setopt($ch, CURLOPT_HEADER, false); //不需要输出头部信息 curl_setopt($ch, CURLOPT_NOBODY, false); //输出内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //超时重试 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //抓取转跳 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); //post方式提交 curl_exec($ch); if (!curl_errno($ch)) { $data = curl_getinfo($ch); } curl_close($ch); return $data; }
    Processed: 0.009, SQL: 9