2

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?

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.

With all the file hosts out there, I am betting there must be a simpler solution.

4

2 回答 2

1

这将是在 Web 服务器级别实现的。如果您使用的是 apache,这个问题可能会涵盖如何实现节流:如何使用 Apache 实现速率限制?(每秒请求数)

至于在每个用户的基础上执行此操作,可能有一种方法可以与来自 php 的这些 apache 配置指令进行交互,或者您可以只拥有两个虚拟主机,其中一个被锁定给某些用户并且具有更高的节流率。

于 2013-04-08T07:43:01.010 回答
0

您可以直接控制 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);
于 2015-08-09T09:03:09.517 回答