如果我使用fopen通过HTTP打开远程文件,将如何获取内容大小


How will get content-size if I open remote file via HTTP using fopen

所以。

$f = fopen('http_url_site_com_my_file_ext');
$info = stream_get_meta_data($f);

http://us1.php.net/manual/ru/function.stream-get-meta-data.php

正如我们在文档中所读到的,我可以在中找到长时间的内容

echo $info['wrapper-data'][#] ; // --> Content-length: 438;

还有

echo $info['wrapper_type']; //--> http

就我而言,我明白cURL而不是http

$info['wrapper-data']['headers']; //empty array

所以我无法得到回应的长度。

===========信息http://www.php.net/manual/en/reserved.variables.httpresponseheader.php

我们可以得到像这样的响应头

$f = fopen('http_url_site_com_my_file_ext');
var_dump($http_response_header); // --> null.
$data = fread($f, 100);
var_dump($http_response_header); // --> array of all response headers.

但这对我的代码来说是非常非常糟糕的。我们在开始时打开了很多文件(如果其中一个是fault-die())

然后,我们从打开的文件中读取。

============问题

1) 如果我将在不使用"--with curlwrappers"的情况下编译php,为什么会出现这个实验特性???---php 5.4.21(php fpm)---在phpinfo中,我没有看到任何构建选项为"--with curlwrappers"

2)或者如何在不读取流的情况下获取响应标头

请帮帮我。

是否必须使用fopen而不是cURL?

此示例适用于cURL

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $http_url_site_com_my_file_ext);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
print_r($r);  

如果启用了http扩展,也可以使用http_head。