下载 - 每个用户的最大连接数? [英] Download - max connections per user?

查看:142
本文介绍了下载 - 每个用户的最大连接数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,允许用户下载简历下载大文件。



这工作正常,但我已经限制下载速度与php代码到200kb / s每个连接。所以,Mozilla的Firefox下载管理器只有一个连接,速度大约200kb / s,但Free-Download-Manager或JDownloader使得2到4个(200Kb / s * 2或4)= 400至800kb / s。

每个用户都可以下载一个连接来下载这个文件? 我认为你的第一件事是禁用 Content-Range ..



14.16内容范围


Content-Range实体标题与部分实体主体一起发送,以指定部分主体应该应用于完整实体主体的哪个位置。范围单位在3.12节定义。

下载管理器可以下载2个或多个连接中的一个罚款,因为范围..如果你禁止在下载简历多个连接无法在单个文件上进行。他们会将每个请求发送到文件开始处
$ b 示例

  LoadModule headers_module modules / mod_headers.so 
Header set Accept-Ranges none
未设置的RequestHeader范围

您还应该查看 14.35.1 Byte Ranges



B 。介绍下载会话。



您可以为每次下载生成一个 uniqid id 并通过PHP页面提供。如果下载仍然处于活动状态或在您刚刚存在该页面之前已经被请求



示例

  $ realFile =test.pdf; 
$ fakeFile = uniqid(file);

$ uniqid = isset($ _ REQUEST ['id'])? $ _REQUEST ['id']:null;
if(empty($ uniqid)|| strlen($ uniqid)< 20 ||!ctype_xdigit($ uniqid)){
die(Die!Die!Die!Stolen URL);
}
$ memcache = new \Memcache();
$ memcache-> connect('localhost',11211);

$ runtime =(int)$ memcache-> get($ uniqid);

if($ runtime){
die(Die!Die!Die!Your Multiple Down loader);
} else {
header(Expires:Mon,1997年7月26日05:00:00 GMT \\\
);
header(Last-Modified:。gmdate(D,d M Y H:i:s)。GMT);
头(Content-Transfer-Encoding:binary);
header(Content-disposition:attachment; filename = $ fakeFile.pdf); //
header('Content-type:application / pdf');
header(Content-length:。filesize($ realFile));
readfile($ realFile);
$ memcache-> set($ uniqid,1);

简单客户端

  $ url =a.php?id =。 bin2hex(mcrypt_create_iv(30,MCRYPT_DEV_URANDOM)); 
printf(< a href ='%s'>下载这里< / a>,$ url);

它会输出类似于

 < a href ='a.php?id = aed621be9d43b0349fcc0b942e84216bf5cd34bcae9b0e33b9d913cccd6e'>下载此处< / a> 

您还需要将每个ID映射到特定文件...

I have a php-script thats allows user to download large files with download resume.

This works fine but I have limited the downloadspeed with php-code to 200kb/s per connection.

So, Mozillas Firefox download manager makes only one connection and the speed is around 200kb/s but Free-Download-Manager or JDownloader makes 2 to 4 connections and so, then the downloadspeed is (200Kb/s * 2 or 4) = 400 to 800kb/s.

How can I stop this and allow only one connection for every user to download this file?

解决方案

A. I think the first thing for you is to disable Content-Range ..

14.16 Content-Range

The Content-Range entity-header is sent with a partial entity-body to specify where in the full entity-body the partial body should be applied. Range units are defined in section 3.12.

Download manager can download a single fine in 2 or multiple connections because of range .. if you disable this both download resume or multiple connections can not be made on a single file. they would make every request to the file start from the beginning

Example

LoadModule headers_module modules/mod_headers.so 
Header set Accept-Ranges none 
RequestHeader unset Range

You should also look at 14.35.1 Byte Ranges

B. Introduce Download Sessions .

You can generate a uniqid id for each download and serve it via PHP page. If the download is still active or has been requested before you just exist the page

Example

$realFile = "test.pdf";
$fakeFile = uniqid("file");

$uniqid = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
if (empty($uniqid) || strlen($uniqid) < 20 || !ctype_xdigit($uniqid)) {
    die("Die! Die! Die! Stolen URL");
}
$memcache = new \Memcache();
$memcache->connect('localhost', 11211);

$runtime = (int) $memcache->get($uniqid);

if ($runtime) {
    die("Die! Die! Die! You Multiple Down loader");
} else {
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Content-Transfer-Encoding: binary");
    header("Content-disposition: attachment; filename=$fakeFile.pdf"); //
    header('Content-type: application/pdf');
    header("Content-length: " . filesize($realFile));
    readfile($realFile);
    $memcache->set($uniqid, 1);
}

Simple Client

$url = "a.php?id=" . bin2hex(mcrypt_create_iv(30, MCRYPT_DEV_URANDOM));
printf("<a href='%s'>Download Here</a>",$url);

It would output something like

<a href='a.php?id=aed621be9d43b0349fcc0b942e84216bf5cd34bcae9b0e33b9d913cccd6e'>Download Here</a>

You also need map each id to a particular file ...

这篇关于下载 - 每个用户的最大连接数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆