使用PHP限制每个用户的服务器上传速度?

时间:2014-07-10 10:38:29

标签: php

我的情况是我需要能够使用PHP限制/限制每个用户的上传速度(传出服务器连接)。原因是因为我为家人和朋友运行了一个小型流媒体网站,目前每个用户都可以用户以最高的速度从服务器下载数据,导致其他用户因我的服务器带宽不足而受损

我做了一些计算,我注意到每个用户只需要 1 Mbps ,以便能够从我的服务器流式传输电影而无需任何缓冲。

所以我的问题是:

如何使用PHP限制/限制每个用户的服务器上传速度?

如果你能提供一个如何实现这一目标的例子,我将非常高兴,因为现在我不知道我怎么能做到这一点。

1 个答案:

答案 0 :(得分:0)

您可以使用bandwidth-throttle/bandwidth-throttle

use bandwidthThrottle\BandwidthThrottle;

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

$throttle = new BandwidthThrottle();
$throttle->setRate(1, BandwidthThrottle::MIBIBYTES); // Set limit to 1MiB/s
$throttle->throttle($out);

stream_copy_to_stream($in, $out);
相关问题