Laravel Limit客户端下载速度(带宽限制)

时间:2017-06-17 10:09:47

标签: laravel bandwidth bandwidth-throttling download-speed

在Laravel中,我可以使用

下载
  

响应() - >下载();

但有没有办法限制客户端速度?

2 个答案:

答案 0 :(得分:0)

据我所知,你不能通过脚本限制下载速度。

答案 1 :(得分:0)

You can use this package:

https://github.com/bandwidth-throttle/bandwidth-throttle

Installation

composer require bandwidth-throttle/bandwidth-throttle

This example will stream a video with a rate of 100KiB/s to the browser:

use bandwidthThrottle\BandwidthThrottle;

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

$throttle = new BandwidthThrottle();
$throttle->setRate(100, BandwidthThrottle::KIBIBYTES); // Set limit to 100KiB/s
$throttle->throttle($out);

stream_copy_to_stream($in, $out);