简体   繁体   English

文件下载速度有限制吗?

[英]Restrictions on file download speed?

I am contemplating setting up a file host (mostly for the exercise) but how do you ensure that free users are only capable of 40-50 kb/s speed while premium users can go at faster speeds? 我正在考虑设置文件主机(主要用于练习),但是如何确保免费用户只能以40-50 kb / s的速度运行,而高级用户却可以以更快的速度运行?

I guess you place all the files on 2 separate servers and simply control the port connection (10 Mbit vs. 1000 Mbit), but that would require a mirror harddisk setup. 我猜您将所有文件放在2台单独的服务器上,只需控制端口连接(10 Mbit与1000 Mbit),但这需要镜像硬盘设置。

With all the file hosts out there, I am betting there must be a simpler solution. 在所有文件托管服务器都存在的情况下,我敢肯定必须有一个更简单的解决方案。

This would be something implemented at the web-server level. 这将是在Web服务器级别实现的。 This question will probably cover how to implement the throttling if you're using apache: How can I implement rate limiting with Apache? 如果您使用的是Apache,则此问题可能会涉及如何实施限制: 如何使用Apache 实施速率限制? (requests per second) (每秒请求数)

As for doing it on a per-user basis there may be a way to interface with these apache configuration directives from php or you could just have two virtual hosts with one being locked down to certain users and with a higher throttle rate. 至于针对每个用户执行此操作,可能有一种方法可以与来自php的这些apache配置指令进行交互,或者您可以只有两台虚拟主机,其中一台被锁定为某些用户使用,并且节流率更高。

You can directly control the bandwidth in PHP userland with eg bandwidth-throttle/bandwidth-throttle 您可以使用例如bandwidth-throttle/bandwidth-throttle直接控制PHP用户bandwidth-throttle/bandwidth-throttle

use bandwidthThrottle\BandwidthThrottle;

$in  = fopen(__DIR__ . "/resources/video.mpg", "r");
$out = fopen("php://output", "w");

$throttle = new BandwidthThrottle();

if ($user->isPremium()) {
    $throttle->setRate(500, BandwidthThrottle::KIBIBYTES); // 500KiB/s
} else {
    $throttle->setRate(50, BandwidthThrottle::KIBIBYTES); // 50KiB/s
}

$throttle->throttle($out);

stream_copy_to_stream($in, $out);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM