2013-11-25 26 views
0

所以。如果我使用fopen通過HTTP打開遠程文件,將如何獲得內容大小

$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 

內容lenth就我而言,我看到 捲曲而不是http

and

$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. 

但它是非常非常壞我的代碼。我們在開始時打開了很多文件(如果其中一個文件是錯誤的 - die())

然後,我們從打開的文件中讀取數據。

============ QUESTION

1)如果我將編譯沒有 「--with-curlwrappers」,爲什麼這個實驗功能是本PHP ??? --- PHP 5.4.21(PHP-FPM) ---中的phpinfo,我看不出有什麼構建選項爲 '--with-curlwrappers' 不讀流

2) 或者我如何能得到響應頭

???

請幫幫我。

回答

0

是否強制使用fopen而不是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_head運行如果啓用了HTTP擴展。

+0

沒有。額外的請求。我沒有空閒時間。一個文件=一個請求。 – user3032727

+0

也,我打開本地文件,將來我會使用套接字,其他協議。 – user3032727

+0

所以我需要相同的接口來讀取數據。 – user3032727

相關問題