栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

仅通过curl在php中检索标头

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

仅通过curl在php中检索标头

您正在将$
header传递给

curl_getinfo()
。应该是
$curl
(卷曲手柄)。您可以
filetime
通过将
CURLINFO_FILETIME
作为第二个参数传递给来获得
curl_getinfo()
。(通常
filetime
是不可用,在这种情况下,它将报告为-1)。

但是,您的课程似乎很浪费,浪费了很多可能有用的信息。这是可以完成的另一种方法:

class URIInfo {    public $info;    public $header;    private $url;    public function __construct($url)    {        $this->url = $url;        $this->setData();    }    public function setData()     {        $curl = curl_init();        curl_setopt($curl, CURLOPT_URL, $this->url);        curl_setopt($curl, CURLOPT_FILETIME, true);        curl_setopt($curl, CURLOPT_NOBODY, true);        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);        curl_setopt($curl, CURLOPT_HEADER, true);        $this->header = curl_exec($curl);        $this->info = curl_getinfo($curl);        curl_close($curl);    }    public function getFiletime()     {        return $this->info['filetime'];    }    // Other functions can be added to retrieve other information.}$uri_info = new URIInfo('http://www.codinghorror.com/blog/');$filetime = $uri_info->getFiletime();if ($filetime != -1) {    echo date('Y-m-d H:i:s', $filetime);} else {    echo 'filetime not available';}

是的,服务器上的负载将减轻,因为它仅返回HTTP标头(毕竟响应

HEAD
请求)。多少打火机会有很大的不同。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442976.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号