[英]Nginx: how to view what files are in downloading state?
我仍然在等待答案。
我需要查看當前是否有人正在下載特定文件。 最初的問題:我想知道何時有人中斷下載文件。
服務器配置:
server
{
listen 80;
server_name mysite.com;
location /ugp/
{
alias /www/ugp/;
}
break;
}
用戶可以從http://mysite.com/ugp/下載文件,例如http://mysite.com/ugp/1.mp3 。
更新 。
顯然,如何分析access.log並非如此。 當用戶停止下載(Google Chrome)時,某些瀏覽器會發送206代碼;而有些瀏覽器則不會發送(HTC Player,移動應用程序):
85.145.8.243 - - [18/Jan/2013:16:08:41 +0300] "GET /ugp/6.mp3 HTTP/1.1" 200 10292776 "-" "HTC Streaming Player htc_wwe / 1.0 / htc_ace / 2.3.5"
85.145.8.243 - - [18/Jan/2013:16:08:41 +0300] "GET /ugp/2.mp3 HTTP/1.1" 200 697216 "-" "HTC Streaming Player htc_wwe / 1.0 / htc_ace / 2.3.5"
85.145.8.243 - - [18/Jan/2013:16:09:44 +0300] "GET /ugp/7.mp3 HTTP/1.1" 200 4587605 "-" "HTC Streaming Player htc_wwe / 1.0 / htc_ace / 2.3.5"
為了提供更大的靈活性,您可以添加一個PHP服務器,並發布URL,例如
http://mysite.com/download.php?file=2.mp3
download.php
從文件所在的位置(例如/var/www/files/2.mp3
)讀取文件,並帶有建議的代碼。 ( 標題 )
<?php
// Here you know precisely that a download is requested
$path = '/home/var/www/files';
$file = "$path/" . $_GET['file']; // check user input!
$size = filesize($file);
$read = 0;
$state = 'downloading ' . $file;
// echo headers for a binary file download
@ $f = fopen ($file, 'r');
if ( $f ) {
// Output 100 bytes in each iteration
while (($chunk = fread($f, 100)) !== false) {
// specify somewhere $state, still downloading
echo $chunk;
$read += strlen($chunk);
}
fclose ($f);
}
if ($read >= $size)
$state = 'done';
else
$state = 'fail';
?>
這是提供算法的一個示例- 完全未經測試! 但是應該與下載代碼非常接近(通常使用readfile ,但它會一次讀取文件)
看一下nginx 擴展狀態模塊 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.