@get_headers下载完整文件还是仅下载元数据


Does @get_headers download the full file or just the metadata?

我的网站上有下载文件,这些文件使用@get_headers来检查文件是否存在并检索内容长度(文件大小)元数据。我最近将下载文件移动到我的 CDN,因为我注意到下载速度提高了 50%,但在移动后,我注意到移动文件后我的 CDN 使用量从每月 5GB 大幅增加到 120GB+。

我想知道@get_headers下载完整文件来检索元数据,还是在不下载完整文件的情况下获取元数据?

如果@get_headers确实下载了完整文件以检索元数据,是否有其他解决方案?

谢谢

它使用 GET,这就是你所说的"完整文件"。 您要做的是使用 HEAD 请求。 这记录在函数的 PHP 页面上的注释中:

<?php
// By default get_headers uses a GET request to fetch the headers. If you
// want to send a HEAD request instead, you can do so using a stream context:
stream_context_set_default(
    array(
        'http' => array(
            'method' => 'HEAD'
        )
    )
);
$headers = get_headers('http://example.com');